Created
January 1, 2012 14:54
-
-
Save mxrguspxrt/1547521 to your computer and use it in GitHub Desktop.
Undrestanding yield and scopes
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
# what should I do, that a() would run in context of class A, not give "block in <main>': undefined method `a' for main:Object (NoMethodError)" | |
class A | |
def a | |
puts "a" | |
end | |
end | |
class B | |
def b(&block) | |
A.module_eval do | |
yield | |
end | |
end | |
end | |
B.new.b do | |
a() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
instance_eval &block saved the day