user2012677
user2012677

Reputation: 5745

method_added, when does it get called? How to call it?

I am confused on how and when method_added(method) gets called.

If I have

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

Why does this not work?

Upvotes: 0

Views: 171

Answers (1)

steenslag
steenslag

Reputation: 80065

This is almost straight from the docs. Note this is plain Ruby, it is not a Rails thing.

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

  def one
  end
end
# => Adding one

Upvotes: 3

Related Questions