- composition instead of inheritance
- autodelegating unknkown methods to composed objects if choice is obvious
Created
July 26, 2012 08:34
-
-
Save paneq/3180999 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 BigBox | |
def method_missing(method) | |
possibilities = instance_variables.map{|ivar| instance_variable_get(ivar) }.select{|obj| obj.respond_to?(method) } | |
super unless possibilities.size == 1 | |
possibilities.first.send(method) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment