Forum: Ruby-core Inconsistency between Enumerable#map and Enumerable#select

B6e5cd9475dd9d8afe7f72457867749b?d=identicon&s=25 Ben Weissmann (Guest)
on 2013-01-24 05:39
(Received via mailing list)
Hey all,

I've found an inconsistency between Enumerable#map and
Enumerable#select,
and i'm wondering what the rationale behind it is:

a = ['a', 'b', 'c']

a.each_with_index.select{|pr| p pr}
# prints:
# ["a", 0]
# ["b", 1]
# ["c", 2]

a.each_with_index.map{|pr| p pr}
# prints:
# "a"
# "b"
# "c"

I've posted this question to StackOverflow [1], and the responses point
to
a difference between the implementation of select and map in both MRI
and
Rubinius. Is there a rationale for this difference, and is
there documentation for which Enumerable methods use which
implementation?

Thanks,
Ben
bsw@mit.edu

[1]
http://stackoverflow.com/questions/14492882/chaini...
This topic is locked and can not be replied to.