How to create an array of methods in rails -
def id_attachment_require_upload? !object.id_attachment? end ... def work_attachment_require_upload? !object.work_attachment? end
i want make below.
array = %w(id address work) array.each |a| def #{a}_attachment_require_upload? !object.#{a}_attachment? end end
is there way me create array of methods automatically in rails save me redundant work.
arup's answer looks it's way go i'm not sure if object.#{a}_attachment?
work. if does, learned new today. can use public_send
.
array = %w[id address work] array.each |a| define_method "#{a}_attachment_require_upload?" !object.public_send("#{a}_attachment?") end end
Comments
Post a Comment