Skip to content

Instantly share code, notes, and snippets.

@dagda1
Created October 21, 2010 07:57
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 dagda1/638091 to your computer and use it in GitHub Desktop.
Save dagda1/638091 to your computer and use it in GitHub Desktop.
autoproperty_init.rb
class Class
def attr_initializer(*attributes)
attr_reader *attributes
class_eval <<-RUBY
def initialize(#{attributes.join(', ')})
#{attributes.map{ |attribute| "@#{attribute}" }.join(', ')} = #{attributes.join(', ')}
end
RUBY
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment