Created
January 15, 2015 16:35
-
-
Save thatandyrose/994edba92cf758400c7f to your computer and use it in GitHub Desktop.
dynamic inheritence
This file contains 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 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