On Apr 11, 2008, at 2:40 PM, Saku Y. wrote:
I was more thinking something along the lines
foo = {}
(‘a’…‘z’).each { |l| foo[l] = somearray.select {dosomething} }So I’d be populating foo hash, with values from somearray according
to some magic. If I’d know I only need to use each value of somearray
once, it would make sense to ‘pop’ the values out from the somearray
in-place.
[ ‘a’, ‘a’, ‘a’ ].select{|x| x == ‘a’}
and you’ve clobbered… not to mention it loses ordering. the only
thing which has semantics inline with that of select is
a.replace a.select(&condition)
which preserves ordering and allows for duplicates.
cheers.