Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby | Hash values function

  • Last Updated : 07 Jan, 2020

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]


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!