Created
August 30, 2013 14:21
-
-
Save pedrocr/6390369 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
class Test | |
def self.hello(name) | |
puts "hello #{name}" | |
end | |
def hello2(name) | |
puts "hello #{name}" | |
end | |
def self.my_create_method(name) | |
define_method(name) do | |
yield "bar" | |
end | |
end | |
#This works | |
my_create_method(:foo) do |obj| | |
self.hello(obj) | |
end | |
#This doesn't work | |
my_create_method(:foo2) do |obj| | |
hello2(obj) | |
end | |
end | |
t = Test.new | |
t.foo # "hello bar" | |
t.foo2 #=> testcase.rb:15:in `block in <class:Test>': undefined method `hello' for Test:Class (NoMethodError) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment