module CallableDict
def method_missing method
puts x["#{method}"]
end
end
The above code is my module, it makes hash keys callable. When I run it though…
require 'callabledict'
x = {"foo" => "ruby"}
x.extend CallableDict
x.foo
I get the following…
SystemStackError: stack level too deep
from /Users/Solomon/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/irb/workspace.rb:80
Maybe IRB bug!
Why? Hpw can I fix this?
actually
xis aselfso you can rewrite it like this: