daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Mar 8th, 2018 57 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. module X
  2.   def x
  3.     "x"
  4.   end
  5.   module_function :x
  6.  
  7.   def self.included(base)
  8.     base.class_eval do
  9.       public :x
  10.     end
  11.   end
  12. end
  13.  
  14. class TestDefault
  15.   include X
  16. end
  17.  
  18. puts TestDefault.new.x
  19. # => x
  20.  
  21.  
  22.  
  23. module OverwriteX
  24.   include X
  25.   def x
  26.     "#{super}2"
  27.   end
  28. end
  29.  
  30. class TestOverwrite
  31.   include OverwriteX
  32. end
  33.  
  34. puts TestOverwrite.new.x
  35. # => x
  36.  
  37.  
  38.  
  39. module DontOverwriteX
  40.   include X
  41. end
  42.  
  43. class TestDontOverwrite
  44.   include DontOverwriteX
  45. end
  46.  
  47. puts TestDontOverwrite.new.x
  48. # => x
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