简体   繁体   English

Sorbet 没有报告丢失的方法实现(与 RBI 签名相比),我在这里做错了什么吗?

[英]Sorbet doesn't report a missing method implementation (compared to an RBI signature), am I doing something wrong here?

I have a file my_class.rb :我有一个文件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 : 安装并初始化 Sorbet 后,我决定在sorbet/rbi/my_class.rbi为此文件编写 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.我特意为adjust方法添加了一个签名,看看 Sorbet 是否会报告它。 But Sorbet doesn't report any errors.但 Sorbet 不会报告任何错误。

Am I configuring Sorbet levels wrong here, or doing something else wrong?我在这里配置的 Sorbet 级别是错误的,还是做错了什么?

Thank you.谢谢你。

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.我是 Sorbet 的新手,但我认为这是因为 RBI 签名不充当传统意义上的“接口”,因此可能描述了实现中不存在的方法。

https://sorbet.org/docs/abstract discusses interfaces and marking a module with interface! https://sorbet.org/docs/abstract讨论接口并用interface!标记模块interface! , I think that may give what you're looking for. ,我认为这可能会提供您正在寻找的内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 Sorbet 认为我在 RBI 文件中提供显式签名的方法不存在? - Why does Sorbet think that a method I provided an explicit signature for in an RBI file doesn't exist? 我发现我缺少了一些东西。 我究竟做错了什么? 黄瓜和正则表达式的麻烦 - I see that I'm missing something. What am I doing wrong? Troubles with cucumber and regex 我在这里做错了什么? 通过设计注册并添加角色 - what am I doing wrong here? Registration with devise and adding a role Ruby“而”我在做什么错 - Ruby “while” what am i doing wrong here 将 Sorbet RBI 文件添加到 gems - Adding Sorbet RBI files to gems 我的Ruby IRC bot没有连接到IRC服务器。 我究竟做错了什么? - My Ruby IRC bot doesn't connect to the IRC server. What am I doing wrong? “ will_paginate”的翻译不起作用。 我究竟做错了什么? - Translation of “will_paginate” doesn't work. What am I doing wrong? QuickBooks API 示例显示了“curl”的用法,但它实际上不起作用,或者我错过了什么 - QuickBooks API example shows usage of “curl” but it actually doesn't work or am I missing something RubyGems是否创建了宝石批处理文件错误或者我错过了什么? - Is RubyGems creating the gem batch file wrong or am I missing something? 我应该如何管理类型信息必须在 rbi 文件中而不是内联的 gem 中的冰糕错误? - How should I manage sorbet errors in a gem where type info must be in rbi files and not inline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM