DEV Community

hiko1129
hiko1129

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

[Ruby][Sorbet] How to write the type of accessor methods (attr_* series methods)

Translate ja to en

class Hoge

  sig {returns(String)} # ← このようにattr_系のメソッドの上にsigを書くだけ
  attr_reader :hoge

end
Enter fullscreen mode Exit fullscreen mode

メソッドコールに対して型定義できるのでそのうちRSpecのletも定義できるような方法が追加されるかも?

参考

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

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. ❤️