Ruby | Hash store() method
Hash#store() is a Hash class method which returns an add on value with the key given by the key-value argument.
Syntax: Hash.store()
Parameter: Hash values
key
value
Return: add on value with the key given by the key-value argument.
Example #1 :
# Ruby code for Hash.store() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, b:200} # declaring Hash value c = {a:100} # strore Value puts "Hash a store form : #{a.store('e', 67)}\n\n" puts "Hash b store form : #{b.store('d', 467)}\n\n" puts "Hash c store form : #{c.store('g', 647)}\n\n" |
chevron_right
filter_none
Output :
Hash a store form : 67 Hash b store form : 467 Hash c store form : 647
Example #2 :
# Ruby code for Hash.store() method # declaring Hash value a = { "a" => 100, "b" => 200 } # declaring Hash value b = {"a" => 100} # declaring Hash value c = {"a" => 100, "c" => 300, "b" => 200} # strore Value puts "Hash a store form : #{a.store('e', 67)}\n\n" puts "Hash b store form : #{b.store('d', 467)}\n\n" puts "Hash c store form : #{c.store('g', 647)}\n\n" puts (a) puts (b) puts (c) |
chevron_right
filter_none
Output :
Hash a store form : 67
Hash b store form : 467
Hash c store form : 647
{"a"=>100, "b"=>200, "e"=>67}
{"a"=>100, "d"=>467}
{"a"=>100, "c"=>300, "b"=>200, "g"=>647}
Recommended Posts:
- Ruby | Hash value? method
- Ruby | Hash < method
- Ruby | Hash > method
- Ruby | Hash replace() method
- Ruby | Hash select() method
- Ruby | Hash to_a method
- Ruby | Hash select!() method
- Ruby | Hash to_h method
- Ruby | String hash method
- Ruby | Hash class >= method
- Ruby | Hash length() method
- Ruby | Hash to_hash method
- Ruby | Hash class <= method
- Ruby | Hash to_s method
- Ruby | Hash to_proc method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



