Last active
March 16, 2017 12:10
-
-
Save dmikurube/d0d238f0bccdb4120768a083f2813329 to your computer and use it in GitHub Desktop.
Hook CONSTANT-like in Ruby
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 M | |
REAL_CONST = 'foo' | |
def self.const_missing(name) | |
if name == :MISSING_DUMMY | |
'qux' | |
else | |
super | |
end | |
end | |
def self.dummy_non_const | |
'bar' | |
end | |
def self.DUMMY_CONST | |
'baz' | |
end | |
end | |
puts M::REAL_CONST | |
puts M::MISSING_DUMMY | |
puts M::dummy_non_const | |
puts M::DUMMY_CONST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.