Skip to content

Instantly share code, notes, and snippets.

@bachue
Created March 3, 2013 12:22
Show Gist options
  • Save bachue/5075906 to your computer and use it in GitHub Desktop.
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
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
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