ruby - Finding the first non-Nil element in an array -
i have code:
default_group_id = @group_list[0].list[0].name
but list member of @group_list[0]
empty code crashes :) need find first @group_list[i]
list member not nil , use that. how can this?
here structure:
you can use enumerable#find:
@group_list.find { |x| !x["list"].blank? } #=> first non-nil , non-empty list in group_list
Comments
Post a Comment