Is inject the same thing as reduce in ruby?

Jacky picture Jacky · Dec 11, 2012 · Viewed 29.3k times · Source

I saw that they were documented together here. Are they the same thing? Why does Ruby have so many aliases (such as map/collect for arrays)? Thanks a lot.

Answer

Zach picture Zach · Dec 11, 2012

Yes, and it's also called fold in many other programming languages and in Mathematics. Ruby aliases a lot in order to be intuitive to programmers with different backgrounds. If you want to use #length on an Array, you can. If you want to use #size, that's fine too!