Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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