Usually when a developer declares a Class in Ruby, they create a initializer method only for assigning some ivars.
[cc lang=”ruby”]
class Car
attr_reader :model, :color
def initialize(model, color)
@ model, @ color = model, color
end
end
[/cc]

My religion forces me to not duplicate code, so I founded a simple solution for monkey patching Class object and add a helper method to abbreviate this casuistry:
[cc lang=”ruby”]
class Car
attr_initializer :model, :color
end
[/cc]

[cc lang=”ruby”]
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 [/cc]