Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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