Ruby | Hash store() method Last Updated : 13 May, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Hash#store() is a Hash class method that returns an add-on value with the key given by the key-value argument. Syntax: Hash.store()Parameter: Hash values key valueReturn: add on value with the key given by the key-value argument. Example #1 : Ruby # 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} # store 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" Output : Hash a store form : 67 Hash b store form : 467 Hash c store form : 647 Example #2 : Ruby # 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} # store 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) 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} Comment More infoAdvertise with us Next Article Ruby | Hash size() method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby Hash-class Similar Reads Ruby | Hash to_s method Hash#to_s() is a Hash class method which gives the string representation of the hash. Syntax: Hash.to_s() Parameter: Hash values Return: string representation of the hash. Example #1 : Ruby # Ruby code for Hash.to_s() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100 1 min read Ruby | String hash method hash is a String class method in Ruby which is used to return a hash based on the string's length, content and encoding. Syntax: str.hash Parameters: Here, str is the given string. Returns: A hash based on the string's length, content and encoding. Example 1: Ruby # Ruby program to demonstrate # the 1 min read Ruby | Hash to_a method Hash#to_a() is a Hash class method which gives a nested array of the key-value pair. Syntax: Hash.to_a() Parameter: Hash values Return: array representation of the hash Example #1 : Ruby # Ruby code for Hash.to_a() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c 2 min read Ruby | Hash to_h method Hash#to_h() is a Hash class method which returns the self - hash representation of the hash Syntax: Hash.to_h() Parameter: Hash values Return: self object Example #1 : Ruby # Ruby code for Hash.to_h() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, b:200} # 1 min read Ruby | Hash size() method Hash#size() is a Hash class method which returns the count of key-value pair in the hash. Syntax: Hash.size() Parameter: Hash values Return: count of key-value pair in the hash. Example #1 : Ruby # Ruby code for Hash.size() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = 1 min read Ruby | Hash shift() method Hash#shift() is a Hash class method which removes a key-value pair from hash and then it returns these value as two-item array. Syntax: Hash.shift() Parameter: Hash values Return: two-item [key-value] array Example #1 : Ruby # Ruby code for Hash.shift() method # declaring Hash value a = {a:455, b:20 2 min read Like