rubymetaprogramming

On which object/class does DelegateClass and similar methods live?


Sorry for the poor title, but I'm a bit lost.

I'm trying to figure out on which object/class live methods such as DelegateClass and what is the term for these types of methods. I'm reading Metaprogramming Ruby and, in the book, these methods are generically called Mimic Methods, but searching the internet for this gives all kinds of results, so I'm wondering if there's a better name for them.

I've checked the source code of DelegateClass and I assumed that it was added to Object, but it's not there. I can see the the classes Delegator and SimpleDelegator, which are in the same rb file, are added as constants (although I'm not sure how they are added).


Solution

  • Just found the answer. It's a private method in Object

    ruby-1.9.2-p290 :033 > Object.private_instance_methods(false).grep /Dele/
     => [:DelegateClass]
    

    edit

    I found out that what I needed to understand is What is the current class? in a given context.