Ruby/Reflection/extend object

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Listen to extension action

module MyMod
  def MyMod.extend_object(obj)
    puts "Extending object id #{obj.id}, type #{obj.type}"
    super
  end
end
 
x = [1, 2, 3]
x.extend(MyMod)
# Output:
# Extending object id 36491192, type Array