Ruby 1.9 regex as a hash key
Posted
by
Liutauras
on Stack Overflow
See other posts from Stack Overflow
or by Liutauras
Published on 2011-03-15T11:32:07Z
Indexed on
2011/03/16
0:09 UTC
Read the original article
Hit count: 120
I am trying this example myhash = {/(\d+)/ => "hello"}
with ruby 1.9.2p136 (2010-12-25) [i386-mingw32].
It doesn't work as expected (edit: as it turned out it shouldn't work as I was expecting):
irb(main):004:0> myhash = {/(\d+)/ => "hello"}
=> {/(\d+)/=>"Hello"}
irb(main):005:0> myhash[2222]
=> nil
irb(main):006:0> myhash["2222"]
=> nil
In Rubular which is on ruby1.8.7 the regex works.
What am I missing?
© Stack Overflow or respective owner