I’m familiarizing myself with Ruby and it’s the first time I see synonyms for methods in the standard library. For now I’ve found the ones in the Enumerable module:
collect <-> map
detect <-> find
include <-> member
etc.
Probably other modules contains synonymic methods too. Why are they there? Is it some kind of backward compatibility? Or is it a feature of the language, so the programmer can choose between different options depending on the context to make the program look like plain English?
I think it is made to be compatible with other programming languages’ word usage.
Ruby is based on Smalltalk. In Smalltalk,
collectmeans map. However, most programming languages in the world usesmap, so Ruby addedmapto make other people feel familiar.See http://en.wikipedia.org/wiki/Map_function for more details.