I suggest the following.
EDIBLE_TYPE = ['fruit','vegetable','nuts']
FOOD_LIST = ['apple','banana','orange','olive','cashew','spinach']
def edible?(food_object)
"%s%s" % [EDIBLE_TYPE.include?(food_object.type) ? 'Edible : ' : '',
FOOD_LIST.include?(food_object.food) ? 'Great Choice !' : '']
end
We can test this by modifying the method slightly.
def edible?(type, food)
"%s%s" % [EDIBLE_TYPE.include?(type) ? 'Edible : ' : '',
FOOD_LIST.include?(food) ? 'Great Choice !' : '']
end
edible?('nuts', 'olive') #=> "Edible : Great Choice !"
edible?('nuts', 'kumquat') #=> "Edible : "
edible?('snacks', 'olive') #=> "Great Choice !"
edible?('snacks', 'kumquat') #=> ""
The operative line of the method could alternatively be written:
format("%s%s", EDIBLE_TYPE.include?(food_object.type) ? 'Edible : ' : '',
FOOD_LIST.include?(food_object.food) ? 'Great Choice !' : ''])
or
"#{EDIBLE_TYPE.include?(food_object.type) ? 'Edible : ' : ''}#{FOOD_LIST.include?(food_object.food) ? 'Great Choice !' : ''}"
See Kernel#format.