Created
May 25, 2011 15:16
-
-
Save niklas/991148 to your computer and use it in GitHub Desktop.
yielding to a block within class_eval does not set self in the block?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A | |
def self.my_eval | |
B.class_eval do | |
puts "self in A.my_eval: #{self}" | |
yield | |
end | |
end | |
end | |
class B | |
A.my_eval do | |
puts "self in B: #{self}" | |
end | |
end | |
A.my_eval do | |
puts "self in top level block: #{self}" | |
end | |
# this will output: | |
# self in A.my_eval: B | |
# self in B: B | |
# self in A.my_eval: B | |
# self in top level block: main | |
# 2 and 4 are really strange.. I would have guessed self would be forwarded within the block. | |
# binding? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment