title: Ruby: How to hook a callback through inheritance
body: <p>I've got some troubles with Ruby about callbacks (and inheritance). Here is my code:</p>
  
  <pre><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 &lt; Lmao
    before_laughing :downcase_please
  
    def downcase_please
      @str.downcase!
    end
  end
  
  a = Lol.new
  a.laughing # =&gt; "HAHAHAHAHAHHAHAHAH"
  </code></pre>
  
  <p>And as you can see, my before laughing callback don't work... because the array @before_laughing is empty.  I believe this can be fixed by editing the way I save *methods into an Lol's instance method (from inside Callbacks).  But I don't really see how...</p>
  
  <p>If you know the solution, thanks for your light!</p>