Skip to content

Instantly share code, notes, and snippets.

@paneq
Created July 26, 2012 08:34
Show Gist options
  • Save paneq/3180999 to your computer and use it in GitHub Desktop.
Save paneq/3180999 to your computer and use it in GitHub Desktop.
  • composition instead of inheritance
  • autodelegating unknkown methods to composed objects if choice is obvious
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