Skip to content

Instantly share code, notes, and snippets.

@axgle
Created October 16, 2009 09:52
Show Gist options
  • Save axgle/211684 to your computer and use it in GitHub Desktop.
Save axgle/211684 to your computer and use it in GitHub Desktop.
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