module CallableDict
def method_missing method
puts x["#{method}"]
end
end
上面的代码是我的模块,它使哈希键可调用。当我运行它时...
require 'callabledict'
x = {"foo" => "ruby"}
x.extend CallableDict
x.foo
我得到以下...
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!
为什么?我可以解决这个问题吗?