Skip to content

Instantly share code, notes, and snippets.

@davidlee
Created March 20, 2009 11:50
Show Gist options
  • Select an option

  • Save davidlee/82329 to your computer and use it in GitHub Desktop.

Select an option

Save davidlee/82329 to your computer and use it in GitHub Desktop.
class Foo
end
class Flibby
def make_method( _method_name )
puts _method_name
Foo.class_eval do
puts _method_name
class << self
define_method _method_name do
puts "yay"
end
end
end
end
end
Flibby.new.make_method "wibble"
[ 22:50 ][ dml@shifter ] % ruby ~/test.rb
wibble
wibble
/home/dml/1.rb:10:in `make_method': undefined local variable or method `_method_name' for #<Class:Foo> (NameError)
from /home/dml/1.rb:7:in `class_eval'
from /home/dml/1.rb:7:in `make_method'
from /home/dml/1.rb:18
zsh: exit 1 ruby ~/1.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment