[ruby-core:115355] [Ruby master Bug#20003] Array#rassoc does not preform implicit conversion

Issue #20003 has been reported by temabolshakov (Tema Bolshakov). ---------------------------------------- Bug #20003: Array#rassoc does not preform implicit conversion https://bugs.ruby-lang.org/issues/20003 * Author: temabolshakov (Tema Bolshakov) * Status: Open * Priority: Normal * ruby -v: 3.2.2 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- 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. ``` ruby 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. -- https://bugs.ruby-lang.org/

Issue #20003 has been updated by temabolshakov (Tema Bolshakov). temabolshakov (Tema Bolshakov) wrote:
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.
``` ruby 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.
I prepared a fix here https://github.com/ruby/ruby/pull/8904 ---------------------------------------- Bug #20003: Array#rassoc does not preform implicit conversion https://bugs.ruby-lang.org/issues/20003#change-105280 * Author: temabolshakov (Tema Bolshakov) * Status: Open * Priority: Normal * ruby -v: 3.2.2 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- 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. ``` ruby 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. -- https://bugs.ruby-lang.org/

Issue #20003 has been updated by mame (Yusuke Endoh). Thanks, I will merge it. ---------------------------------------- Bug #20003: Array#rassoc does not preform implicit conversion https://bugs.ruby-lang.org/issues/20003#change-105429 * Author: temabolshakov (Tema Bolshakov) * Status: Open * Priority: Normal * ruby -v: 3.2.2 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- 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. ``` ruby 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. -- https://bugs.ruby-lang.org/
participants (2)
-
mame (Yusuke Endoh)
-
temabolshakov (Tema Bolshakov)