Ruby | Hash values function
Hash#values() is a Hash class method which returns the values present in the hash.
Syntax: Hash.values()
Parameter: Hash values
Return: hash values
Example #1 :
# Ruby code for Hash.values() 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} # values Value puts "Hash a values form : #{a.values()}\n\n" puts "Hash b values form : #{b.values()}\n\n" puts "Hash c values form : #{c.values()}\n\n" |
chevron_right
filter_none
Output :
Hash a values form : [100, 200] Hash b values form : [100, 300, 200] Hash c values form : [100]
Example #2 :
# Ruby code for Hash.values() 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} # values Value puts "Hash a values form : #{a.values()}\n\n" puts "Hash b values form : #{b.values()}\n\n" puts "Hash c values form : #{c.values()}\n\n" |
chevron_right
filter_none
Output :
Hash a values form : [100, 200] Hash b values form : [100] Hash c values form : [100, 300, 200]
Recommended Posts:
- Ruby | Hash any?() function
- Ruby | Hash key() function
- Ruby | Hash each() function
- Ruby | Hash key?() function
- Ruby | Hash eql? function
- Ruby | Hash dig() function
- Ruby | Hash merge function
- Ruby | Hash merge! function
- Ruby | Hash compare_by_identity () function
- Ruby | Hash inspect() function
- Ruby | Hash member? function
- Ruby | Hash fetch function
- Ruby | Hash fetch_values() function
- Ruby | Hash flatten() function
- Ruby | Range hash() 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.



