Skip to content

Instantly share code, notes, and snippets.

@jasim
Created September 30, 2012 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasim/3806147 to your computer and use it in GitHub Desktop.
Save jasim/3806147 to your computer and use it in GitHub Desktop.
a simple example of method_missing and why you should use it with care
class Item
attr_reader :id
def initialize(id, properties)
@id = id
@properties = properties
end
def method_missing(m, *args, &block)
@properties[m]
end
end
i=Item.new(1, {:name => "car", :color => "red"})
p i.color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment