Skip to content

Instantly share code, notes, and snippets.

@mxrguspxrt
Created January 1, 2012 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxrguspxrt/1547521 to your computer and use it in GitHub Desktop.
Save mxrguspxrt/1547521 to your computer and use it in GitHub Desktop.
Undrestanding yield and scopes
# 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
@mxrguspxrt
Copy link
Author

instance_eval &block saved the day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment