user730569 user730569 - 15 days ago 6
Ruby Question

calling .map on the first X elements of an array

I want to call .map on only the first X elements of an array. How do I do this?

Answer

In ruby 1.9

array.first(X).map{|e| ...}

In ruby 1.8

array[0, X].map{|e| ...}
Comments