Skip to content

Instantly share code, notes, and snippets.

@ehaliewicz
Created November 22, 2012 01:58
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 ehaliewicz/4129020 to your computer and use it in GitHub Desktop.
Save ehaliewicz/4129020 to your computer and use it in GitHub Desktop.
class Class
def attr_accessor_with_default(attr_name, val)
attr_name = attr_name.to_s
self.class_eval("def #{attr_name}; @#{attr_name} = #{val};end")
self.class_eval("@#{attr_name} = #{val}")
self.class_eval("def #{attr_name}=(val) @#{attr_name} = val end")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment