Ruby | Hash replace() method Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report Hash#replace() : replace() is a Hash class method which replaces the content of one hash with other. Syntax: Hash.replace() Parameter: Hash values Return: replaces the content of one hash with other. Example #1 : Ruby # Ruby code for Hash.replace() 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} # replace Value puts "Hash a replace form : #{a.replace(b)}\n\n" puts "Hash b replace form : #{b.replace(c)}\n\n" puts "Hash c replace form : #{c.replace(a)}\n\n" Output : Hash a replace form : {:a=>100, :c=>300, :b=>200} Hash b replace form : {:a=>100} Hash c replace form : {:a=>100, :c=>300, :b=>200} Example #2 : Ruby # Ruby code for Hash.replace() 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} # replace Value puts "Hash a replace form : #{a.replace(b)}\n\n" puts "Hash b replace form : #{b.replace(c)}\n\n" puts "Hash c replace form : #{c.replace(a)}\n\n" Output : Hash a replace form : {"a"=>100} Hash b replace form : {"a"=>100, "c"=>300, "b"=>200} Hash c replace form : {"a"=>100} Comment More infoAdvertise with us Next Article Ruby | Hash > method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby Hash-class Similar Reads Ruby | Hash reject! method Hash#reject!() is a Hash class method which checks whether any changes are made in the hash array or not Syntax: Hash.reject!() Parameter: Hash values Return: true - if changes are made otherwise return false Example #1 : Ruby # Ruby code for Hash.reject!() method # declaring Hash value a = { " 1 min read Ruby | Hash reject method Hash#reject() is a Hash class method which returns a new hash which consists of entries for which the block returns false. Syntax: Hash.reject() Parameter: Hash values Return: new hash which consists of entries for which the block returns false. enumerator - If no block is given Example #1 : Ruby # 2 min read Ruby | Hash to_proc method Hash#to_proc() : to_proc() is a Hash class method which returns a Proc which maps 'keys' value to 'value' value. Syntax: Hash.to_proc() Parameter: Hash values Return: Proc which maps 'keys' value to 'value' value. Example #1 : Ruby # Ruby code for Hash.to_proc() method # declaring Hash value a = {a: 2 min read Ruby | Hash < method Hash#<() is a Hash class method which compares two Hash values. Syntax: Hash.<() Parameter: Hash values Return: true - if a < b otherwise return false Example #1 : Ruby # Ruby code for Hash.<() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, b:2 1 min read Ruby | Hash > method Hash#>() is a Hash class method compares two Hash values. Syntax: Hash.>() Parameter: Hash values Return: true - if a > b otherwise return false Example #1 : Ruby # Ruby code for Hash.>() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, b:200} # 2 min read 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 Like