Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我注意到类变量 @@my_class var 现在在 Ruby 1.9.1 中的 instance_eval'd 对象的上下文中查找,而在 Ruby 1.8.6 中并非如此。
Ruby 1.9.1 的 instance_eval 行为还有哪些其他差异?
我无法将它们全部列出,但我知道不断查找有一些变化。在 1.8 中,常量查找是在调用者范围内,而在 1.9 中是在块范围内。
FOO = "hi" class Something FOO = "bye" def self.handle(&block) instance_eval(&block) end end p Something.handle { FOO } # "hi" on 1.8, "bye" on 1.9
我认为它[至少目前]也不会返回自我。