title: How can I dynamically add/extend methods from a Class?
body: <p>I'm using a Ruby Component inside an Audio Application Environment. This Ruby Component is represented by an instance of a <code>RubyEdit</code> class. This provide the interface between my Ruby code and the Environment. </p>
  
  <p>For example if I write <code>self</code> it outputs the instance of the RubyEdit class that represents that component:</p>
  
  <p><a href="https://i.stack.imgur.com/Ekazh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ekazh.png" alt="enter image description here"></a></p>
  
  <p>the nice things is that I can/must "implement/extend" some methods that <code>RubyEdit</code> will call when it get some events. I can define my custom method <code>event</code> for that instance:</p>
  
  <pre><code>def event
      # my own event code
  end
  </code></pre>
  
  <p>and it will be called when the Environment get some events outside this Ruby Component. Or I can call a <code>class method</code> called <code>redraw</code>, and it will call my custom method <code>draw</code>:</p>
  
  <pre><code>  def draw
       # my own draw code (this will called after invoking redraw from Ruby Component)
    end
  </code></pre>
  
  <p>I need to understand some hierarchy of this process, so I'm making a simulation of that <code>RubyEdit</code> class in Ruby. </p>
  
  <p>How it will looks? I mean: how can I provide methods that will be defined "later"?</p>
  
  <p>This is how RubyEdit will look I think:</p>
  
  <pre><code>class RubyEdit
    def self.redraw
      # calling this class method should invoke my extended draw method
    end
  
    def draw
    end
  
    def event
    end
  end
  </code></pre>
  
  <p>but I don't understand how to place <code>event</code> and <code>draw</code> methods extendible. Interfaces?</p>