Guest User

Untitled

a guest
Apr 25th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. module M
  2. def self.included(base)
  3. base.constants.each do |const|
  4. # we need to transfer the including class Constants so that they can be accessed from
  5. # the TemplatedGenerator instance methods
  6. self.const_set(const, eval("#{base}::#{const}"))
  7. end
  8. end
  9.  
  10. def display_constant
  11. puts "Module M needs to access the #{SomeConstant}"
  12. end
  13.  
  14. end
  15.  
  16. class A
  17. SomeConstant = "Constant from A"
  18. include M
  19. end
  20.  
  21. class B
  22. SomeConstant = "Constant from B"
  23. include M
  24. end
  25.  
  26.  
  27.  
  28. a = A.new
  29. a.display_constant
  30.  
  31. b = B.new
  32. b.display_constant
Add Comment
Please, Sign In to add comment