G
Garret Kelly
Hi,
I'm sure if I'm missing something fundamental, but when you run the
code below with comments intact it won't execute, claiming that:
../test.rb:13:in `something': undefined method `some_function' for
#<B:0x2b9c102564a8> (NoMethodError)
from ../test.rb:30
When the comments are removed, the code will run. The thing I can't
understand is why, when the comments are in-place, the call to
some_function from within an instance of B doesn't work. Can anyone
point me in the right direction?
Thanks,
Garret
class A
def self.some_function(param)
puts "param: #{param}"
end
# def some_function(*args)
# puts self
# B.some_function(*args)
# end
def self.register(name, &block)
define_method(name) do |*args|
some_function("thing")
block.call(args)
end
end
def initialize
puts "I'm a #{self.class}"
end
end
class B < A
register :something do |*args|
some_function("something")
end
end
b = B.new
b.something
I'm sure if I'm missing something fundamental, but when you run the
code below with comments intact it won't execute, claiming that:
../test.rb:13:in `something': undefined method `some_function' for
#<B:0x2b9c102564a8> (NoMethodError)
from ../test.rb:30
When the comments are removed, the code will run. The thing I can't
understand is why, when the comments are in-place, the call to
some_function from within an instance of B doesn't work. Can anyone
point me in the right direction?
Thanks,
Garret
class A
def self.some_function(param)
puts "param: #{param}"
end
# def some_function(*args)
# puts self
# B.some_function(*args)
# end
def self.register(name, &block)
define_method(name) do |*args|
some_function("thing")
block.call(args)
end
end
def initialize
puts "I'm a #{self.class}"
end
end
class B < A
register :something do |*args|
some_function("something")
end
end
b = B.new
b.something