Open In App
Related Articles

Ruby | Hash values function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
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"

                    
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"

                    
Output :
Hash a values form : [100, 200]

Hash b values form : [100]

Hash c values form : [100, 300, 200]



Last Updated : 07 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads