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:

enter image description here

you can use enumerable#find:

@group_list.find { |x| !x["list"].blank? } #=> first non-nil , non-empty list in group_list 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -