Turns out I have a hash :
inventario = {"Notebooks"=> 4, "PC Escritorio"=> 6, "Routers"=> 10, "Impresoras"=> 6}
I need to update the information regarding any product, and for the inventory to be updated.
I tried with map
, hashmap
and put
, but it seems I'm not using them correctly.
To update the value of a key in a hash, simply assign a new value directly using the Hash#[]= method ; for instance:
To change inventory from
"Notebooks"
to5
:Since the values are numbers, you can use
+
or-
; For example, if you sell 2"Impresoras"
(inventory decrease), you could do the following:Finally, you can substitute values for variables, assuming they come from another section of code in your application; for instance: