Skip to content

Instantly share code, notes, and snippets.

@Lara-zz
Created June 2, 2009 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Lara-zz/122106 to your computer and use it in GitHub Desktop.
Save Lara-zz/122106 to your computer and use it in GitHub Desktop.
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