ruby on rails 3 - Specify attribute list in attr_accessor with method call -
i want create large number of attributes can done ease if constructed method call this,
attr_accessor :attr_list def attr_list [:x1, :y1, :x2, :y2] end
this not working. there other way achieve this?
any appreciated.
figured out,
def self.attr_list [:x1, :y1, :x2, :y2] end attr_accessor *attr_list
explanation:
as attr_accessor method call expects parameters list. can not pass array is. (*) convert array parameters list.
just need define class method returning array of attribute list passed attr_accessor.
works attr_accessible(or similar) well.
Comments
Post a Comment