Skip to content

Instantly share code, notes, and snippets.

@Naomi-Dennis
Last active January 16, 2020 20:57
Show Gist options
  • Save Naomi-Dennis/1b0a50374e957aa84e06c3ddcdb34c0d to your computer and use it in GitHub Desktop.
Save Naomi-Dennis/1b0a50374e957aa84e06c3ddcdb34c0d to your computer and use it in GitHub Desktop.
class ShopItem
attr_reader :value, :name
def initialize(value, name)
@value = value
@name = name
end
end
# -- snip --
def items
[ShopItem.new(20, "Paper"),
ShopItem.new(50, "Ball"),
ShopItem.new(40, "Book"),
ShopItem.new(4, "Chips")]
end
def find_item(item_name)
items.select do | item |
item.name == item_name
end.first
end
item = "Ball"
searched_item = find_item(item)
unless searched_item.nil?
money = perform_transaction(money, searched_item)
else
puts "We don't sell that item"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment