SHARE
TWEET

method_added and singleton_method_added

cd62131 May 26th, 2017 (edited) 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top