method_added,什么时候被调用?怎么称呼它?

我对method_added(method)的调用方式和时间感到困惑。

如果我有

class Car

  def method_added(method)
    puts 'method added called'
    super
  end

  def one
    puts 'one method'
  end

  def two
    puts 'two method'
  end

end

Car.new.one

为什么这不起作用?

ptpstao 回答:method_added,什么时候被调用?怎么称呼它?

这与the docs差不多。请注意,这是普通的Ruby,而不是Rails。

class Car
  def self.method_added(method_name)
    puts "Adding #{method_name}"
  end

  def one
  end
end
# => Adding one
本文链接:https://www.f2er.com/3130886.html

大家都在问