Steep - Gradual Typing for Ruby
Installation
Install via RubyGems.
$ gem install steep
Requirements
Steep requires Ruby 2.6 or later.
Usage
Steep does not infer types from Ruby programs, but requires declaring types and writing annotations You have to go on the following three steps.
0. steep init
Run steep init
to generate a configuration file.
$ steep init # Generates Steepfile
Edit the Steepfile
:
target :app do
check "lib"
signature "sig"
library "set", "pathname"
end
1. Declare Types
Declare types in .rbs
files in sig
directory.
class Person
@name: String
@contacts: Array[Email | Phone]
def initialize: (name: String) -> untyped
def name: -> String
def contacts: -> Array[Email | Phone]
def guess_country: -> (String | nil)
end
class Email
@address: String
def initialize: (address: String) -> untyped
def address: -> String
end
class Phone
@country: String
@number: String
def initialize: (country: String, number: String) -> untyped
…