I have a working code as below. Is there any better way to return nil
after the each
loop and unless else
in the below example?
def find_member(member_name)
unless members.empty?
members.each do |member|
if member.name == member_name
return member
end
end
nil
else
nil
end
end
I should pass nil
in each case because there are different conditions in other methods where this method is called. That is the reason why I have written the code as above.