Skip to content
Related Articles

Related Articles

Ruby | Hash rassoc() function
  • Last Updated : 07 Jan, 2020

rassoc() is an Hash class method which searches an element through the Hash value.

Syntax: Hash.rassoc()

Parameter: Hashs for finding elements.

Return: searches an element through the Hash value

Example #1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for rassoc() method
  
# declaring Hash value
a = { "a" => "abc", "b" => "200" }
  
# declaring Hash value
c = {"a" => 100, "c" => 300, "b" => 200}
  
puts "check : #{a.rassoc("200")}\n\n"
  
puts "check : #{c.rassoc(300)}\n\n"
  
puts "check : #{c.rassoc(100)}\n\n"

chevron_right


Output :

check : ["b", "200"]

check : ["c", 300]

check : ["a", 100]

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for rassoc() method
  
# declaring Hash value
a = { "a" => "geek", "b" => "200" }
  
# declaring Hash value
c = {"a" => "abc", "c" => 300, "b" => 200}
  
puts "check : #{a.rassoc("geek")}\n\n"
  
puts "check : #{c.rassoc(300)}\n\n"
  
puts "check : #{c.rassoc("abc")}\n\n"

chevron_right


Output :

check : ["a", "geek"]

check : ["c", 300]

check : ["a", "abc"]
My Personal Notes arrow_drop_up
Recommended Articles
Page :