Created
March 3, 2013 12:22
-
-
Save bachue/5075906 to your computer and use it in GitHub Desktop.
Try to catch a uninitialized constant error and then load the missing file and necessary 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
def Object.const_missing(const_name, *args) | |
puts "const_missing #{const_name.inspect}" | |
require './test_class' | |
Object.const_get const_name | |
end | |
obj = TestClass.new | |
puts obj.f # => hello world |
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
class TestClass | |
def f | |
'hello world' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment