Skip to content

Instantly share code, notes, and snippets.

@osyo-manga
Created December 19, 2020 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osyo-manga/89e763bb7cb6ad57b55d5ce54e010980 to your computer and use it in GitHub Desktop.
Save osyo-manga/89e763bb7cb6ad57b55d5ce54e010980 to your computer and use it in GitHub Desktop.

kanazawa.rb meetup #100

自己紹介


3行で分かる Ruby 3.0 の型チェック

  • 型情報を .rbs ファイルという別ファイルで定義する
  • Ruby 3.0 では標準で型チェックを行うような機能は入らない
  • Ruby のコードから .rbs ファイルを自動生成するツールが入る

実際に型チェックしてみる

  • Steep という外部ツールを使って型チェックできる
# Steepfile
target :app do
  check "./"
  signature "./"

  library "set", "pathname"
end
class User
  attr_reader :name, :age

  def initialize(name:, age:)
    @name = name
    @age = age
  end
end

User.new(name: "homu", age: "14")
# Classes
class User
  attr_reader name: String
  attr_reader age: Integer
  def initialize: (name: String, age: Integer) -> Integer
end
$ steep check

詳しくは以下を読んでね

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment