Skip to content

Instantly share code, notes, and snippets.

@jjuliano
Last active December 16, 2019 11:07
Show Gist options
  • Save jjuliano/1c32b106f61f931be48da78db0a6f3ee to your computer and use it in GitHub Desktop.
Save jjuliano/1c32b106f61f931be48da78db0a6f3ee to your computer and use it in GitHub Desktop.
class Basket
def initialize
@basket = []
end
def add_item(kind, **item)
@basket << item.merge({kind: kind})
puts "Entry #{item[:name]} created!"
puts
end
def print_items
puts "There are #{@basket.count} item(s) in the basket."
puts
@basket.each do |entry|
puts "Name: #{entry[:name]}"
puts "Flavour: #{entry[:flavour]}"
puts "Kind: #{entry[:kind]}"
puts
end
end
end
basket = Basket.new
basket.add_item(
"fruit",
name: "apple",
flavour: "It's a little sour and bitter, but mostly sweet, not at all salty, very juicy in general."
)
basket.print_items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment