Skip to content

Instantly share code, notes, and snippets.

@carlzulauf
Forked from thejonanshow/dynamical.rb
Last active August 29, 2015 14:07
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 carlzulauf/3b67f58db8e4a2014232 to your computer and use it in GitHub Desktop.
Save carlzulauf/3b67f58db8e4a2014232 to your computer and use it in GitHub Desktop.
class Dynamical
def should_not_explode(&block)
5.times { |n| yield n }
end
define_method :works_fine do |&block|
5.times { |n| block.call(n) }
end
def also_works_fine(&block)
5.times { |n| block.call(n) }
end
define_method :explodes, self.new.method(:should_not_explode)
def seems_like_it_should_explode
5.times { |n| yield n }
end
end
d = Dynamical.new
d.works_fine {|x| puts x}
d.also_works_fine {|x| puts x}
d.seems_like_it_should_explode {|x| puts x}
d.explodes {|x| puts x}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment