On Fri, Feb 20, 2009 at 2:11 PM, Glenn Little <[email protected]> wrote:
>
> I think this is a philosophical ruby question.
>
Most of it is.
>
> Why does ruby allow fixnums to be accessed as hashes?
>
It's a bitmap (although, maybe I'm just pointing out the obvious).
>> 5[0]
=> 1
>> 5[1]
=> 0
>> 5[2]
=> 1
The rest is a philosophical question, and you make a very good point that I
think I mostly agree with.
> Array.new()[:some_key]
> TypeError: Symbol as array index
>
That error should probably be thrown from...
>> 5[:some_key]
as well. And it will in Ruby 1.9...
[~] % irb1.9
irb(main):001:0> 5[:some_key]
TypeError: can't convert Symbol into Integer
from (irb):1:in `[]'
from (irb):1
from /usr/local/bin/irb1.9:12:in `<main>'
Darren
--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---