Hi!

I'm trying to add a method dynamically to a class by opening an existing
class, and it actually works. What I don't understand is why it doesn't
show up when I use the "methods" method on it afterwards.

What I do is something like this:
Code:

def method_missing name, *args

   Array.class_eval "def #{name} *args; #{str}; end"

end

Afterwards I can call that method on every object of this class (new or
otherwise). However, it doesn't show up in Array.methods.

The Array.methods.length is the same both before and after that line is
executed and adds the method. However, if I do a self.methods.length the
number of methods has increased.

My question is therefore this: how can I add a method to a class (e.g.
Array) and have it show up when I do a <class>.methods on it?


Thanks in advance for any help!
-- 
Posted via http://www.ruby-forum.com/.