Created
March 17, 2022 01:35
-
-
Save ianks/6e98ec4ab1d51f2c36972db13c792520 to your computer and use it in GitHub Desktop.
Sorbet wrapper method?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How would I write a sig such that #wrapped_start the same type signature | |
# as the subclass' #start method (i.e. Car#start or Boat#start) | |
class Vehicle | |
def wrapped_start | |
start | |
end | |
end | |
class Car < Vehicle | |
sig { params(key: String, license: License).returns(T::Boolean) } | |
def start(key) | |
# .... | |
end | |
end | |
class Boat < Vehicle | |
sig { params(key: String).returns(T::Boolean) } | |
def start(key) | |
# .... | |
end | |
end | |
# Desired sig: | |
# sig { params(key: String, license: License).returns(T::Boolean) } | |
Car.new.wrapped_start(key: "1234") #=> should complain about missing "license" param | |
# Desired sig: | |
# sig { params(key: String).returns(T::Boolean) } | |
Boat.new.wrapped_start(key: "1234", license: drivers_license) #=> should complain about extra "license" param |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment