Hash#inspect() is a Hash class method which gives the string representation of hash.
Syntax: Hash.inspect()
Parameter: Hash values
Return: string representation of the hash
Exaample #1 :
# Ruby code for Hash.inspect() 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} # inspect Value puts "Hash a inspect form : #{a.inspect()}\n\n" puts "Hash b inspect form : #{b.inspect()}\n\n" puts "Hash c inspect form : #{c.inspect()}\n\n" |
chevron_right
filter_none
Output :
Hash a inspect form : {:a=>100, :b=>200}
Hash b inspect form : {:a=>100, :c=>300, :b=>200}
Hash c inspect form : {:a=>100}
Example #2 :
# Ruby code for Hash.inspect() 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} # inspect Value puts "Hash a inspect form : #{a.inspect()}\n\n" puts "Hash b inspect form : #{b.inspect()}\n\n" puts "Hash c inspect form : #{c.inspect()}\n\n" |
chevron_right
filter_none
Output :
Hash a inspect form : {"a"=>100, "b"=>200}
Hash b inspect form : {"a"=>100}
Hash c inspect form : {"a"=>100, "c"=>300, "b"=>200}
Recommended Posts:
- Ruby | Rational inspect() function
- Ruby | Array class inspect() function
- Ruby | Time inspect function
- Ruby | Range inspect() function
- Ruby | Struct inspect() function
- Ruby | Regexp inspect() function
- Ruby | Symbol inspect function
- Ruby | StringScanner inspect function
- Ruby | String inspect Method
- Ruby | Hash each_pair() function
- Ruby | Hash to_s() function
- Ruby | Hash invert() function
- Ruby | Hash include?() function
- Ruby | Array class hash() function
- Ruby | Hash rassoc() function
- Ruby | Hash delete_if() function
- Ruby | Hash delete() function
- Ruby | Hash compare_by_identity? () function
- Ruby | Hash compact!() function
- Ruby | Hash compact() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

