I'm having trouble with Ruby about callbacks (and inheritance). Here is my code:
class Lmao def initialize @str = "HAHAHAHAHAHHAHAHAH" @before_laughing = [] end def self.inherited(base) base.extend(Callbacks) end def laughing @before_laughing.each {|method| send(method) } @str end end module Callbacks def before_laughing(*methods) @before_laughing = methods end end class Lol < Lmao before_laughing :downcase_please def downcase_please @str.downcase! end end a = Lol.new a.laughing
And, as you can see, my laugh back call does not work ... because the @before_laughing array is empty. I believe that this can be fixed by editing the method for saving * methods in the Lol instance method (from inside Callbacks). But I really don't see how ...
If you know the solution, thanks for your light!
source share