-
-
Save godfat/1599287 to your computer and use it in GitHub Desktop.
How to invoke Module#constants on Module itself
This file contains 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
X = 1 | |
# Module.constants returns constants accessible at the place where the | |
# method is called. | |
p Module.constants.include?(:X) #=> true | |
# Module#constants returns constants defined in the receiver. However, | |
# you need a trick to invoke Module#constants on Module itself. | |
p Module.instance_method(:constants).bind(Module).call #=> [] | |
p Module.instance_method(:constants).bind(Object).call.include?(:X) #=> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment