The to_hash()
method is a hash class method that returns the hash representation of the hash itself.
Hash.to_hash()
Hash
: This is the hash whose hash representation we want to get.
Self object: This method returns the same hash.
# create hashesh1 = {one: 1, two: 2, three: 3}h2 = {name: "okwudili", stack: "ruby"}h3 = {"foo": 0, "bar": 1}h4 = {M:"Mango", A: "Apple", B: "Banana"}# invoke to_hash() methodputs h1.to_hash()puts h2.to_hash()puts h3.to_hash()puts h4.to_hash()
to_hash()
method on the hashes. Then, we print the results to the console.