Last active
January 16, 2020 20:57
-
-
Save Naomi-Dennis/1b0a50374e957aa84e06c3ddcdb34c0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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