Ruby | Array rassoc() operation

Array#rassoc() : rassoc() is an Array class method which searches an element through the array.

Syntax:  Array.rassoc()

Parameter: 
- Arrays for finding elements. 
- elements to detect

Return:  Array after adding the elements at the end.

Code #1 : Example for rassoc() method

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for rassoc() method
   
# declaring array
a = [18, 22, 33, 4, 5, 6]
   
# declaring array
b = [5, 4, 22, 1, 88, 9]
   
# declaring array
c = [18, 22, 33, 40, 50, 16]
  
ar = [a, b, c]
  
# searhing for an element
puts "check : #{ar.rassoc(4)}\n\n"
  
puts "check : #{ar.rassoc(22)}\n\n"

chevron_right


Output :

check : [5, 4, 22, 1, 88, 9]

check : [18, 22, 33, 4, 5, 6]

Code #2 : Example for rassoc() method

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for rassoc() method
   
# declaring array
a = ["abc", "xyz", "dog"]
   
# declaring array
b = ["cow", "cat", "dog"]
   
# declaring array
c = ["cat", "1", "dog"]
  
ar = [a, b, c]
  
  
# searhing for an element
puts "check : #{ar.rassoc("xyz")}\n\n"
  
puts "check : #{ar.rassoc("1")}\n\n"

chevron_right


Output :

check : ["abc", "xyz", "dog"]

check : ["cat", "1", "dog"]



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.