Created
August 10, 2012 21:11
-
-
Save benhamill/3318006 to your computer and use it in GitHub Desktop.
Define method has helpful stack traces, compared to other meta-programming stuff.
This file contains hidden or 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
class Foo | |
%w(bar baz).each do |m| | |
define_method("say_#{m}") do | |
raise m.to_s | |
end | |
end | |
end | |
f = Foo.new | |
f.say_bar |
This file contains hidden or 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
$ ruby code.rb | |
code.rb:4:in `block (2 levels) in <class:Foo>': bar (RuntimeError) | |
from code.rb:11:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment