Peña, Botp
9/12/2008 1:27:00 AM
From: David A. Black [mailto:dblack@rubypal.com]=20
.
#For a little while, 1.9 allowed you to do this:
#>> e =3D [1,2,3].enum_for(:map, &lambda {|x| x * 10 })
#=3D> #<Enumerable::Enumerator:0x39038c>
#>> e.select {|n| n > 10 }
#=3D> [20, 30]
#But #enum_for no longer accepts a &block-style argument. The same code
#in current 1.9 would give you [], because it would ignore the lambda
#and just do a pass-through mapping.
#I'm still unclear as to why this behavior was removed. It seems to me
#that its removal reduces the usefulness of enumerators drastically.
maybe because it does not look any better than the simpler (but less =
efficient)
> e =3D [1,2,3].select{|n| n>1}.map{|x| x*10}
=3D>[20,30]
i was actually dreaming of ruby supporting multiple blocks
so that you can do simply
> e =3D [1,2,3].select{|n| n>1},{|x| x*10}
=3D>[20,30]
meaning, do a (re)map if a second code block is passed
kind regards -botp