Ruby | Hash to_proc method
Last Updated :
07 Jan, 2020
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 :
a = {a: 100 , b: 200 }
b = {a: 100 , c: 300 , b: 200 }
c = {a: 100 }
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 :
a = { "a" => 100 , "b" => 200 }
b = { "a" => 100 }
c = { "a" => 100 , "c" => 300 , "b" => 200 }
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 : #
Share your thoughts in the comments
Please Login to comment...