Method: Immutable::Hash#rassoc

Defined in:
lib/immutable/hash.rb

#rassoc(obj) ⇒ Array

Searches through the Hash, comparing obj with each value (using ‘#==`). When a matching value is found, return the `[key, value]` pair as an array. Return nil if no match is found.

Examples:

Immutable::Hash["A" => 1, "B" => 2, "C" => 3].rassoc(2)  # => ["B", 2]

Parameters:

  • obj (Object)

    The value to search for (using #==)

Returns:

  • (Array)


675
676
677
678
# File 'lib/immutable/hash.rb', line 675

def rassoc(obj)
  each { |entry| return entry if obj == entry[1] }
  nil
end