Compare object attributes with array of objects Ruby on Rails -
i have object want compare array of objects. if 2 specific attributes equal want stop loop. how can that, or how can in better rails way?
@item #item compare @items.each |item| if ( (item.att1 == @item.att1) && (item.att3 == @item.att3) ) is_equal(item.id) else #do end end
use find method of array:
matched_item = @items.find { | item | item.att1 == @item.att1 && item.att1 == @item.att1 } is_equal(matched_item.id)
Comments
Post a Comment