Skip to content

Instantly share code, notes, and snippets.

@mpalmer
Forked from activefx/gist:5460d9236ba0ba7f1800
Last active August 29, 2015 14:18
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 mpalmer/7297631d4236479744da to your computer and use it in GitHub Desktop.
Save mpalmer/7297631d4236479744da to your computer and use it in GitHub Desktop.
class Example
def make_method(&block)
@block = block
end
def dynamic_method(n)
@block.call(n) if @block
end
end
example = Example.new
example.make_method do |n|
n + 1
end
if example.dynamic_method(1) == 2
puts "OK"
else
puts "FAIL"
puts "Expected 2, got #{example.dynamic_method(1).inspect}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment