module ReadIngredients
class << self
include Enumerable
def each
while input = gets.chomp
break if end_of_input?(input)
yield input
end
end
alias_method :with_object, :each_with_object
private
def end_of_input?(input)
input == 'done'
end
end
end
ingredients = ReadIngredients.with_object([]) do |ingredient, ingredients|
ingredients << ingredient
end
puts ingredients