I tried to implement a class allowing its subclasses to save method blocks for get them executed later. It work's, but it seems I took the wrong way. Have a look at this:
class SuperKlass
def self.exec_later(&block)
@@block_for_later = block
end
def exec_now
return unless @@block_for_later
@@block_for_later.call
end
end
class ChildKlass < SuperKlass
exec_later do
child_method
end
def child_method
puts "Child method called"
end
end
test_klass = ChildKlass.new
test_klass.exec_now
If I try to execute this piece of code, the call to child_method in the block results in a method-missing error. Does somebody know what I'm doing wrong, and what's the right way to add functionality like this?