Ruby is a traditionally dynamically typed language. It is one of the reasons many Ruby developers love working with the language. Yet, static type checking is coming to Ruby, and with it comes many opportunities to make our code more explicit, more thoroughly understood by future developers and more resilient.
Sorbet is an open-source gem that introduces static type checking to your existing codebase incrementally. It lets you reduce the pain in the process by gradually increasing the severity of the check you run. Using the sigil
# typed: you can designate a precise level of check, or none at all, on each file in your codebase.
In this three-part series, we walk through the first steps in introducing Sorbet to your code. Part 1 will take you through installation and initialization of the gem. Part 2 will take you through running the first code quality checks. Part 3 will introduce the first method signatures and run the first checks on types.
The state of static type checking in Ruby is a constantly evolving one. A solution now might not be applicable down the road as new approaches are developed. This is an exciting space to keep on watching and developing in.
Are you working with static type checking in Ruby or in another traditionally dynamically typed language? How has it gone for you? What have you experienced?
Ruby Minutes is a new video series from Nexmo that looks at new and interesting things in the Ruby ecosystem. Have a topic you'd like us to feature? Let us know! We'd love to hear from you.