It's time to make it shorter:
class Foo
attr_accessor :a, :b, :c, :d, :e
def initialize(a, b, c, d, e)
@a = a
@b = b
@c = c
@d = d
@e = e
end
end
We have 'attr_accessor' to generate getters and setters.
Do we have anything to generate initializers by attributes?
Easiest:
Generates both accessors and initializer. You can further customize your class with:
We can create something like
def_initializer
like this:You can use a gem like constructor. From the description:
It is easily used:
If you don't want the ivars generated with accessors, you can leave off the :accessors => true
Hope this helps /Salernost