Advertisement
cd62131

method_added and singleton_method_added

May 26th, 2017
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.65 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. module DefineHook
  4.   def self.included(other)
  5.     puts "#{other} include #{self}"
  6.     puts "ancestors: #{other.ancestors}"
  7.   end
  8.   def self.extended(other)
  9.     puts "#{other} extend #{self}"
  10.     puts "singleton_class.ancestors: #{other.singleton_class.ancestors}"
  11.   end
  12.   def method_added(name)
  13.     puts "#{self}##{name} added"
  14.     super
  15.   end
  16.   def singleton_method_added(name)
  17.     puts "#{self}.#{name} added"
  18.     super
  19.   end
  20. end
  21.  
  22. module Foo
  23.   class << self; include DefineHook; end
  24.   def foo1; end
  25.   module_function :foo1
  26.   def self.foo2; end
  27. end
  28.  
  29. class Bar
  30.   extend DefineHook
  31.   def bar1; end
  32.   def self.bar2; end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement