Differences in instance_eval behaviour between Ruby 1.9.1 and 1.8.6?
Question
I noticed that class variables @@my_class var are now looked up in the context of the instance_eval'd object in Ruby 1.9.1 whereas this was not the case in Ruby 1.8.6.
What are some other differences in behaviour of instance_eval for Ruby 1.9.1 ?
Solution
I can't list them all, but I know that there are some changes in constant lookup. In 1.8, constant lookup was in the callers scope, while it is in the blocks scope in 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
OTHER TIPS
I think it [at least currently] doesn't return self, either.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow