I am trying this example myhash = {/(\\d+)/ => \"hello\"} with ruby 1.9.2p136 (2010-12-25) [i386-mingw32]. It doesn\'t work as exp
myhash = {/(\\d+)/ => \"hello\"}
Are you looking for this behaviour?
myhash = Hash.new{|h,k| h[k] = 'hello' if k =~ /(\d+)/} p myhash['aaa'] #=> nil p myhash #=> {} p myhash['1234'] #=>" hello" p myhash #=> {"1234"=>"hello"}