How to use the guard clause in the following scenario? The msg
is capturing info in 2 independent if-clauses.
def edible?(food_object)
edible_type = ['fruit','vegetable','nuts']
food_list = ['apple','banana','orange','olive','cashew','spinach']
food = food_object.food
type = food_object.type
msg = ''
if edible_type.include?(type)
msg += 'Edible : '
end
if food_list.include?(food)
msg += 'Great Choice !'
end
end
Like this:
or to return as early as possible
Side note: Beware that the commonly accepted practice is for the ruby method names to end with
?
when they return boolean value.