Created
June 2, 2009 06:38
-
-
Save Lara-zz/122106 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
def update_product | |
product.each{ |key, value| | |
puts "#{key} - #{value[0]}, #{value[1]}" | |
} | |
print "Enter the key number of the product you wish to update: " | |
$stdout.flush | |
keynumber = gets.chomp.upcase | |
print "Enter 9 to change the product name, or 10 to change the price: " | |
$stdout.flush | |
entry = gets.chomp.to_i | |
if entry == 9 | |
if product.has_key?(keynumber) | |
puts product[key, value] | |
print "Enter the new product name: " | |
$stdout.flush | |
new_name = gets.chomp.upcase | |
puts new_name | |
product.delete(key, value) | |
puts product.inspect.upcase | |
elsif ! product.has_key?(keynumber) | |
print "This product is not in the list.\n" | |
end | |
end | |
if entry == 10 | |
if product.has_value?(name) | |
print "Enter the new product price: " | |
$stdout.flush | |
new_price = gets.chomp.to_f | |
product[ key ][price].upcase = new_price | |
puts product.inspect.upcase | |
end | |
end | |
end | |
case choice | |
when 1 | |
add_product | |
end | |
when 2 | |
update_product | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment