I'm relatively new to Ruby, so this is a pretty general question. I have found through the Ruby Docs page a lot of methods that seem to do the exact same thing or very similar. For example
I am a bit confused by your specific examples:
collectare aliases. They don't "do the exact same thing", they are the exact same thing. They are just two names for the same method. You can use whatever name you wish, or what reads best in context, or what your team has decided as a Coding Standard. The Community seems to have settled on
collectare completely different, there is no similarity there, apart from the general fact that they both operate on collections.
maptransform a collection by mapping every element to a new element using a transformation operation. It returns a new collection (an
Array, actually) with the transformed elements.
eachperforms a side-effect for every element of the collection. Since it is only used for its side-effect, the return value is irrelevant (it might just as well return
Kernel#putsdoes, in languages like C, C++, Java, C♯, it would return
void), but it is specified to always return its receiver.
Strings based on a delimiter that can be either a
Regexp(in which case you can also influence whether or not the delimiter itself gets captured in the output or ignored) or a
nil(in which case the global default separator gets used).
Arraywith the individual characters (represented as
Strings of length 1, since Ruby doesn't have an specific
charsbelongs together in a family with
codepointswhich do the same thing for
splitcan only be used as a replacement for one of the methods in this family (
splitis much more general than that.
So, in the examples you gave, there really isn't much similarity at all, and I cannot imagine any situation where it would be unclear which one to choose.
In general, you have a problem and you look for the method (or combination of methods) that solve it. You don't look at a bunch of methods and look for the problem they solve.
There'll typically be only one method that fits a specific problem. Larger problems can be broken down into different subproblems in different ways, so it is indeed possible that you may end up with different combinations of methods to solve the same larger problem, but for each individual subproblem, there will generally be only one applicable method.