Guest User

Untitled

a guest
Apr 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. module M
  2.  
  3. def base_constant(constant)
  4. self.class.const_get(constant)
  5. end
  6.  
  7. def display_constant
  8. puts "Module M needs to access the #{base_constant(:SOME_CONSTANT)}"
  9. end
  10.  
  11. end
  12.  
  13. class A
  14. SOME_CONSTANT = "Constant from A"
  15. include M
  16. end
  17.  
  18. class B
  19. SOME_CONSTANT = "Constant from B"
  20. include M
  21. end
  22.  
  23. a = A.new
  24. a.display_constant
  25.  
  26. b = B.new
  27. b.display_constant
Add Comment
Please, Sign In to add comment