Ruby | Hash to_proc method Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report 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:100, b:200} # declaring Hash value b = {a:100, c:300, b:200} # declaring Hash value c = {a:100} # to_proc Value puts "Hash a to_proc form : #{a.to_proc()}\n\n" puts "Hash b to_proc form : #{b.to_proc()}\n\n" puts "Hash c to_proc form : #{c.to_proc()}\n\n" Output : Hash a to_proc form : # Hash b to_proc form : # Hash c to_proc form : # Example #2 : Ruby # Ruby code for Hash.to_proc() 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} # to_proc Value puts "Hash a to_proc form : #{a.to_proc()}\n\n" puts "Hash b to_proc form : #{b.to_proc()}\n\n" puts "Hash c to_proc form : #{c.to_proc()}\n\n" Output : Hash a to_proc form : # Hash b to_proc form : # Hash c to_proc form : # Comment More infoAdvertise with us Next Article Ruby | Hash to_s method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby Hash-class Similar Reads 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_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 | 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 store() method 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 H 2 min read 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 Like