class X
class << self
def attr_string arg
eval("def #{arg}; return #{arg.to_s}; end")
end
end
end
是我正在使用的代碼。我試圖將它變成類宏,比如attr_accessor。當我打電話爲什麼我在此代碼中獲取SystemStackError?
foo = 50
X.attr_string :foo
X.foo
我得到一個SystemStackError
。爲什麼是這樣?
'X.foo'應該返回什麼?在你的情況下,它應該返回'foo' – fl00r