Created
February 10, 2010 15:51
-
-
Save michael-erasmus/300462 to your computer and use it in GitHub Desktop.
This file contains 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 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