Created
August 17, 2011 12:29
-
-
Save watson/1151439 to your computer and use it in GitHub Desktop.
How to access a class constant dynamically from inside a module when the module is included into the class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Foo | |
def foo | |
# This does not work: | |
# TYPES | |
# This works: | |
self.class.const_get('TYPES') | |
end | |
end | |
class Bar | |
TYPES = 'You found me!' | |
include Foo | |
end | |
Bar.new.foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment