Skip to content

Instantly share code, notes, and snippets.

@thatandyrose
Created January 15, 2015 16:35
Show Gist options
  • Save thatandyrose/994edba92cf758400c7f to your computer and use it in GitHub Desktop.
Save thatandyrose/994edba92cf758400c7f to your computer and use it in GitHub Desktop.
dynamic inheritence
class SomeObject
def initialize(object_to_extend)
@object_to_extend = object_to_extend
end
def respond_to?(sym, include_private = false)
super(sym, include_private) || object_to_extend_responds?(sym)
end
def method_missing(sym, *args, &block)
return object_to_extend.send(sym, *args, &block) if object_to_extend_responds?(sym)
super(sym, *args, &block)
end
def object_to_extend_responds?(sym)
object_to_extend.respond_to?(sym)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment