DEV Community

hiko1129
hiko1129

Posted on • Originally published at note.hiko1129.com on

[Ruby][Sorbet] T::Struct == is an identity comparison, not an equivalence comparison

Translate ja to en

T::Structの==は、hashや通常のStructと異なり同値性ではなく同一性比較になっています。

class Hoge < T::Struct
  const :hoge, Integer
end

a = Hoge.new(hoge: 1)
b = Hoge.new(hoge: 1)

a == b # => false
a == a # => true
Enter fullscreen mode Exit fullscreen mode

issue: https://github.com/sorbet/sorbet/issues/1540
同値性比較用のgem: https://github.com/bellroy/sorbet-struct-comparable

Top comments (0)