RubyMonk 跟踪方法

RubyMonk Tracking Methods

所以我完全不知道它要我做什么。

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

所以我很好地满足了上面的要求。我的问题围绕以下...

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

---下面的屏幕截图--- http://imgur.com/Cjbmd2K

我对我要做什么一无所知,有人请帮帮我。我已经被这个问题困扰了几个小时了。我很绝望。我敢肯定它很简单,但我就是一辈子都做不到。请换双眼睛!

我不喜欢他们在这里的说明含糊不清,而且他们没有为您提供任何 "hints" 或 "see solutions"。快把我逼疯了!

我终于想通了,我昨天离开了它,直到今天早上。我想新鲜的眼睛有帮助。

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