Skip to content

Instantly share code, notes, and snippets.

@brianstorti
Created November 20, 2011 16:16
Show Gist options
  • Save brianstorti/1380420 to your computer and use it in GitHub Desktop.
Save brianstorti/1380420 to your computer and use it in GitHub Desktop.
attr_create (attr_accessor like)
class Module
def attr_create(*symbols)
symbols.each do |symbol|
class_eval("def #{symbol}; @#{symbol}; end;")
class_eval("def #{symbol}=(value); @#{symbol} = value; end;")
end
end
end
class A
attr_create :name, :programming_language
end
a = A.new
a.name = "Brian"
a.programming_language = "Ruby"
puts a.name
puts a.programming_language
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment