Ruby code + RBS. • Ruby3 will ship with RBS (+ stdlib signatures). • RBS (+ stdlib signatures) will release as a gem for 2.7 soon. • Type checkers won't be a part of Ruby.
Will rename to RBS ($ gem install rbs). • PR is open on ruby/ruby for migration. • PRs from Rubyists! • Improvements on .rbs files • Improvements on test features
from IDE? I don't want to type check my code. RBS is not DRY! My code is small. Cannot justify the extra cost for type checking. I don't want to write types. What if a gem doesn't provide RBS? How can I write RBS for this? How about duck typing?
• Open class • Union types • Method overloading • Doesn't support • Array#map! • Meta programming • Conditional mixin a = [1,2,3] a.map! { @1.to_s } class GPU include Win32 if os.windows? include Metal if os.mac? end attr_reader :user belongs_to :group attr_gzip :content
checker • LSP based integrations provide better coding experience. • Cons • You have to take care of RBS • You have to write type-checking compatible code
checker • LSP based integrations provide better coding experience. • Cons • You have to take care of RBS • You have to write type-checking compatible code
Type checkers allows mixing typed and untyped Ruby code. • App code vs test code. • Models vs controller. • This file cannot be typed. lib/student.rb eval <<-SRC class Student def method_missing(name, *args) case name when :first_name @first_name sig/student.rbs class Student attr_reader first_name: String attr_reader last_name: String def initialize: (String, String) -> void end
use type checker. • Pros • You can help your gem users type check their programs. • You don't have to write type-checker compatible code. • Cons • You cannot type check.
• List of methods/classes of untyped is okay. • Write methods you really need to type check your code. class CSV def self.read: (String) -> Array[Array[String]] end sig/polyfill/csv.rbs class IO def self.popen: (*untyped args) -> untyped end sig/polyfill/io.rbs
Integer < Numeric include JSON::Ext::Generator::GeneratorMethods::Integer def self.sqrt: (untyped) -> untyped public def %: (untyped) -> untyped def &: (untyped) -> untyped def *: (untyped) -> untyped Prints list of classes, modules, includes and methods. Replace untypeds with precise types.
from IDE? I don't want to type check my code. RBS is not DRY! My code is small. Cannot justify the extra cost for type checking. I don't want to write types. What if a gem doesn't provide RBS? How can I write RBS for this? How about duck typing?