Skip to content

Instantly share code, notes, and snippets.

@activefx
Created April 4, 2015 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save activefx/5460d9236ba0ba7f1800 to your computer and use it in GitHub Desktop.
Save activefx/5460d9236ba0ba7f1800 to your computer and use it in GitHub Desktop.
class Example
def make_method(&block)
line_no = __LINE__; method_defs = %{
def dynamic_method
#{block}.call(1)
end
}
instance_eval method_defs, __FILE__, line_no
end
end
example = Example.new
example.make_method do |n|
n + 1
end
# expect to be 2
example.dynamic_method
#=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment