Reputation: 4755
I have a file my_class.rb
:
# typed: true
class MyClass
attr_accessor :a, :b
def initialize(a: 1, b: 2)
@a = a
@b = b
end
def do_stuff
puts "#{self.class}: #@a #@b"
a * b + a - b
end
end
After installing and initializing Sorbet, I decided to write an RBI signature for this file in sorbet/rbi/my_class.rbi
:
# typed: strict
class MyClass
sig { params(a: Numeric, b: Numeric).void }
def initialize(a:, b:); end
sig { returns(Numeric) }
def a; end
sig { returns(Numeric) }
def b; end
sig { returns(Numeric) }
def do_stuff; end
sig { params(x: Numeric).void }
def adjust(x); end;
end
I deliberately added a signature for an adjust
method to see if Sorbet would report on it. But Sorbet doesn't report any errors.
Am I configuring Sorbet levels wrong here, or doing something else wrong?
Thank you.
Upvotes: 1
Views: 408
Reputation: 11076
I'm new to Sorbet, but I think this is because the RBI signatures don't act as an 'interface' in the traditional sense, so may describe methods that don't exist in the implementation.
https://sorbet.org/docs/abstract discusses interfaces and marking a module with interface!
, I think that may give what you're looking for.
Upvotes: 2