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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️