Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module M
- def self.included(base)
- base.constants.each do |const|
- # we need to transfer the including class Constants so that they can be accessed from
- # the TemplatedGenerator instance methods
- self.const_set(const, eval("#{base}::#{const}"))
- end
- end
- def display_constant
- puts "Module M needs to access the #{SomeConstant}"
- end
- end
- class A
- SomeConstant = "Constant from A"
- include M
- end
- class B
- SomeConstant = "Constant from B"
- include M
- end
- a = A.new
- a.display_constant
- b = B.new
- b.display_constant
Add Comment
Please, Sign In to add comment