Skip to content

Instantly share code, notes, and snippets.

@aderyabin
Created May 3, 2011 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aderyabin/953511 to your computer and use it in GitHub Desktop.
Save aderyabin/953511 to your computer and use it in GitHub Desktop.
create_attr
def create_method(name, &block)
self.class.send(:define_method, name, &block)
end
def create_attr_methods(name)
create_method("#{name}=".to_sym) { |val| instance_variable_set("@" + name, val) }
create_method(name.to_sym) { instance_variable_get("@" + name) }
end
def create_attr(name, value = nil)
create_attr_methods(name.to_s)
instance_variable_set("@" + name.to_s, value)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment