Skip to content

Instantly share code, notes, and snippets.

@henrik
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrik/9314943 to your computer and use it in GitHub Desktop.
Save henrik/9314943 to your computer and use it in GitHub Desktop.
class Module
def const_missing(const_name)
puts "[ModuleConstMissing] #{self} missing #{const_name}"
end
end
class FakeDelegator < BasicObject
def self.const_missing(name)
puts "[FakeDelegator] missing #{name}"
if ::Object.const_defined?(name)
::Object.const_get(name)
else
super if defined?(super)
end
end
end
class MyObject1
File
NoSuch
end
puts
class MyObject2 < FakeDelegator
File
NoSuch
end
[ModuleConstMissing] MyObject1 missing NoSuch
[FakeDelegator] missing File
[FakeDelegator] missing NoSuch
[ModuleConstMissing] MyObject2 missing NoSuch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment