RubyMonk Tracking Methods

123 Views Asked by At

So I am completely lost on what Its asking me to do.

https://rubymonk.com/learning/books/5-metaprogramming-ruby-ascent/chapters/31-lifecycle-hooks/lessons/70-introduction-lifecycle-callbacks

Tracking methods

The addition of a method to a class or module is a logical place to begin. >method_added is an instance method on Module and consequently inherited into ?>Class. When you're using it, you simply implement the method as an instance >method on the class (or module) - so it's a self method, basically - and listen >for the names of methods that are added.

The only information it receives from the runtime is the name of the method, in >the form of a Symbol.

Lifecycle callbacks are simple enough to understand that you will understand it >very quickly with a little practice. Here's an exercise for you to try it out - >simply make the tests pass.

class Dojo
   @@methods_added = []

     def self.methods_added
       @@methods_added
    end

    def self.method_added(method_name)
       @@methods_added << method_name
    end
end

So I got the request above perfectly fine. My question revolves around the following...

Tracking singleton methods is identical, except that you use the >singleton_method_added lifecycle callback instead of method_added. >singleton_method_added being of a more fundamental nature is defined on >BasicObject.

The only interesting difference from method_added worth noting is that since >singleton_method_added is itself a singleton method, it receives a callback - >about itself - as soon as it's added.

Let's dive straight into an exercise.

class Dojo
   @@singleton_methods_added = []

     def self.singleton_methods_added
        @@singleton_methods_added
     end
end

---Screen Shot BELOW--- https://i.stack.imgur.com/TbrMn.jpg

I haven't the foggiest idea as to what I am looking to do, someone please help me out here. I've been suck on this for a couple of hours now. Im desperate. I'm sure its something very simple but I just can't get it for the life of me. New set of eyes please!

I don't like how they are vague on the instructions here, plus they don't provide you with any "hints" or "see solutions". Driving me bonkers!

1

There are 1 best solutions below

2
On BEST ANSWER

I finally figured it out, I walked away from it yesterday till this morning. I guess fresh eyes helped.

class Dojo
   @@singleton_methods_added = []

def self.singleton_methods_added
  @@singleton_methods_added
end

def self.singleton_method_added(method_name)
  @@singleton_methods_added << method_name
   end
end