Skip to content

Instantly share code, notes, and snippets.

@benhamill
Created August 10, 2012 21:11
Show Gist options
  • Save benhamill/3318006 to your computer and use it in GitHub Desktop.
Save benhamill/3318006 to your computer and use it in GitHub Desktop.
Define method has helpful stack traces, compared to other meta-programming stuff.
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
$ 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