Guest User

Untitled

a guest
Feb 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. module Fuller
  2. module ClassMethods
  3. def classy
  4. puts "a mixed in class method"
  5. end
  6. end
  7.  
  8. module InstanceMethods
  9. def insticky
  10. puts "a mixed in instance method"
  11. end
  12. end
  13.  
  14. module CommonMethods
  15. def everywhere
  16. puts "a mixed in method for both class and instance"
  17. end
  18. end
  19.  
  20. def self.included(klass)
  21. klass.extend(ClassMethods)
  22. klass.extend(CommonMethods)
  23. klass.send(:include, CommonMethods)
  24. klass.send(:include, InstanceMethods)
  25. end
  26. end
  27.  
  28. class MyKlass
  29. include Fuller
  30. end
  31.  
  32. MyKlass.classy #=> "a mixed in class method"
  33. MyKlass.new.insticky #=> "a mixed in instance method"
  34. MyKlass.everywhere #=> "a mixed in method for both class and instance"
  35. MyKlass.new.everywhere #=> "a mixed in method for both class and instance"
Add Comment
Please, Sign In to add comment