You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to define == for objects when using Array#delete #6262
Defining == method on an object so that it's used for comparison when using Array#delete causes an exception. For some reason, the other becomes an Object, rather than Cell.
Sample code
classCellattr_accessor:iddefinitialize@id=rand(1_000_000)enddef ==(other)@id == other.idenddefid@idendendcells=Array.new(1_000){Cell.new}1_000.timesdo |i|
cells.delete(cells.sample)endputs"There are #{cells.size} cells left."
Activity
phi-luna commentedon May 9, 2024
this error seems to not occur at current master (19d9f48)
it seems to have been fixed by 14bd875
pusewicz commentedon May 9, 2024
@leviongit I played around, and in fact it's an issue with the
Array#index:Expected
Actual
mruby-enum-ext: use NONE.equal?() for NONE comparison; ref #6262
mruby-enumerator: use NONE.equal?() for NONE comparison; ref #6262
mruby-hash-ext: use NONE.equal?() for NONE comparison; ref #6262
matz commentedon May 10, 2024
As general advice, the
==method should accept any object as an argument. But we fixed the issue anyway.mruby-array-ext: use NONE.equal?() for NONE comparison; fix mruby#6262
pusewicz commentedon May 12, 2024
@matz That's correct, but in my case I knew exactly that there would be only one type of object in the array.
matz commentedon May 13, 2024
Despite of your expectation
==method may be called from the library. In fact, the bug was in thefindmethod calling==.