Project

General

Profile

Actions

Bug #20003

closed

Array#rassoc does not preform implicit conversion

Added by temabolshakov (Tema Bolshakov) about 1 year ago. Updated about 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:115355]

Description

There is a difference between behaviour of Array#assoc and Array#rassoc. The first one performs implicit conversion (calls #to_ary) while the former does not.

class ArrayConvertible
  def initialize(*values)
    @values = values;
  end

  def to_ary
    @values
  end
end

s1 = [1, 2]
s2 = ArrayConvertible.new(2, 3)
a = [s1, s2]

The a.assoc(2) call returns [2, 3] as expected. However, a.rassoc(3) returns nil

Expected behaviour: a.rassoc(3) returns [2, 3] in such cases.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0