Peña, Botp
7/11/2005 10:18:00 AM
nobuyoshi nakada [mailto:nobuyoshi.nakada@ge.com] wrote:
#> You're vague plan produces clearer ruby..
#>
#> but isn't
#> each_with_index.map
#>
#> so close to being
#> map_with_index
#>
#> ?
#>
#> (1..6).map_with_index{|x,i|[2,5].include?(i) ? x : x*2} is
#very easy to my
#> tiny brain since all i have to remember is map (just like
#(in array) all i
#> have to focus is each, then i follow thru with each_with_index)
#
#What about Enumerator#with_index?
#
# [1,2,3,4,5,6].map.with_index {|x,i|[2,5].include?(i) ? x : x*2}
imho, #with_index pleads for a better name. It sounds far from being a
method; which leads me to incline back to your original proposition of
each_with_index.map...
another concern also is that sir matz already warned me of the spilling of
the *_with_index naming all over the place..
OK, i'll be shooting for the moon here. How about passing a parameter? Is it
then possible to make #each or #map same behavior w #each_with_index or
#map_with_index or whatever *_with_index so that the ff works,
def each(with_index=true) do... end
def map(with_index=true) do ... end
and thus, we can do
[1,2,3,4,5,6].map(true) {|x,i|[2,5].include?(i) ? x : x*2}
I think this one does not break old code, no?
I find index being more of an attribute than a pure method.
And you are all right, I just need the index, why do i need another set of
methods?
Again, imho.
Thanks and kind regards -botp
#
#--
#Nobu Nakada
#