Skip to content

Instantly share code, notes, and snippets.

@ianks
Created March 17, 2022 01:35
Show Gist options
  • Save ianks/6e98ec4ab1d51f2c36972db13c792520 to your computer and use it in GitHub Desktop.
Save ianks/6e98ec4ab1d51f2c36972db13c792520 to your computer and use it in GitHub Desktop.
Sorbet wrapper method?
# 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