Skip to content

Instantly share code, notes, and snippets.

@michael-erasmus
Created February 10, 2010 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save michael-erasmus/300462 to your computer and use it in GitHub Desktop.
Save michael-erasmus/300462 to your computer and use it in GitHub Desktop.
class Expando
def method_missing(method_id, *arguments)
if match = method_id.id2name.match(/(\w*)(\s*)(=)(\s*)(\.*)/)
puts match[1].to_sym
self.class.class_eval{ attr_accessor match[1].to_sym }
instance_variable_set("#{match[1]}", match[5])
else
super.method_missing(method_id, *arguments)
end
end
end
person = Expando.new
person.name = "Michael"
person.surname = "Erasmus"
person.age = 29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment