title: What's the best strategy for get/setting metadata on Ruby methods at runtime?
body: <p>I have a class with some methods. It's supersekret but I've reproduced what I can here.</p>
  
  <pre><code>Class RayGun
    # flashes red light
    # requires confirmation
    # makes "zowowowowowow" sound
    def stun!
      # ...
    end
  
    # flashes blue light
    # does not require confirmation
    # makes "trrrtrtrtrrtrtrtrtrtrtr" sound
    def freeze!
      # ...
    end
  
    # doesn't flash any lights
    # does not require confirmation
    # makes Windows startup sound
    def killoblast!
      # ...
    end
  end
  </code></pre>
  
  <p>I want to be able to, at runtime, interrogate the class about one of the methods and receive a hash or struct like so:</p>
  
  <pre><code>  {:lights =&gt; 'red', :confirmation =&gt; false, :sound =&gt; 'windows'}
  </code></pre>
  
  <p>What's the best way of doing this? Obviously you could have separate YAML file alongside and set up a convention to relate the two, but ideally I want code and metadata in one place.</p>
  
  <p>The most promising idea I can come up with is something like this:</p>
  
  <pre><code>class RayGun
    cattr_accessor :metadata
    def self.register_method(hsh)
      define_method(hsh.name, hsh.block)
      metadata[hsh[:name]] = hsh
    end
  
    register_method({
      :name =&gt; 'stun!', 
      :lights =&gt; 'red', 
      :confirmation =&gt; 'true', 
      :sound =&gt; 'zowowo',
      :block =&gt; Proc.new do
        # code goes here
     })
  
     # etc.
  end
  </code></pre>
  
  <p>Anyone got some better ideas? Am I barking up a very wrong tree?</p>