Created
October 16, 2009 09:52
-
-
Save axgle/211684 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Module | |
def field(*args) | |
args.each do |m| | |
class_eval do | |
define_method("#{m}="){|a| | |
instance_variable_set("@#{m}",a) | |
} | |
define_method("#{m}"){ | |
instance_variable_get("@#{m}") | |
} | |
end | |
end | |
end | |
end | |
class Person | |
field :name,:age | |
end | |
a=Person.new | |
a.name="axgle" | |
a.age=25 | |
p a | |
p a.instance_variable_get("@name") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment