From: Jason Nordwick Date: 2006-09-16T00:12:19+09:00 Subject: Re: arbitrary indexes In my original message, I asked for people not to answer "change the behavior of [] yourself" beause changing the base semantics of indexing is likely to play havoc with the other developers (we have about 5 writing with the same code) or possibly another package we import (this type of collision has already happened once to us on a relatively small project, and we had to turn off an couple inlined C method because of it). "Change the base behavior of this builtin" and "write it in C" have become the chief dodges of the Ruby community to any substantive criticism. I now have a file I load that includes base extensions to the language that should probably be supplied by the system, and that files seems to just keep growing. Ruby is become less productive of a langauge because of it because I spend more time either searching for these functions like "values_at", writing extentions to [] or such, and then debugging them when the interactions with other parts of the system fail. -j MonkeeSage wrote: > Jason Nordwick wrote: >> Of course I don't believe that going from value_at to [] would make >> my code faster, just that it would make it more compact. We started >> using Ruby for some moderately heavy numerics, and I haven't been >> able to be as concise (or productive) as I wish (or thought from what >> others told me). > > So define your own implementation! That's one of the things that makes > working in ruby so productive. > > class Array > def [](*args) > if args.size == 1 > at(*args) > else > values_at(*args) > end > end > end > > a = [1,2,3,4,5,6,7,8,9] > p a[2] # => 3 > p a[2,4,6] #=> [3, 5, 7] > > Regards, > Jordan > >