Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何从混合模块调用'self.class'?_Ruby_Sorbet - Fatal编程技术网

Ruby 如何从混合模块调用'self.class'?

Ruby 如何从混合模块调用'self.class'?,ruby,sorbet,Ruby,Sorbet,我有一个模块要包括在其他课程中。它使用如下方法: () #键入:true 模块M 德福 自我阶级 结束 结束 对此,雪糕说 editor.rb:4: Method class does not exist on M https://srb.help/7003 4 | self.class ^^^^^^^^^^ Did you mean to `include Object` in this module? ???: Did you mean:

我有一个模块要包括在其他课程中。它使用如下方法: ()

#键入:true
模块M
德福
自我阶级
结束
结束
对此,雪糕说

editor.rb:4: Method class does not exist on M https://srb.help/7003
     4 |    self.class
            ^^^^^^^^^^
  Did you mean to `include Object` in this module?
    ???: Did you mean: Object#class?
现在它变得有趣了。确实描述了这可以防止BasicObject中包含的模块中的类型错误。很好,所以我包括Object,正如检查器告诉我的:()

#键入:true
模块M
包含对象
德福
自我阶级
结束
结束
错误消息毫无帮助,链接的文件不存在

editor.rb:2: Only modules can be included. This module or class includes Object https://srb.help/5032
     2 |module M
        ^^^^^^^^
我花了一段时间才意识到,它试图告诉我,我不能包含一个作为模块子类的类。与Ruby的错误消息进行比较:

$ ruby -e 'module M; include Object; end'
Traceback (most recent call last):
        2: from -e:1:in `<main>'
        1: from -e:1:in `<module:M>'
-e:1:in `include': wrong argument type Class (expected Module) (TypeError)
$ruby-e'模块M;包括客体;结束'
回溯(最近一次呼叫最后一次):
2:from-e:1:in`'
1:from-e:1:in`'
-e:1:'include'中:错误的参数类型类(应为模块)(TypeError)
如何使我的代码通过此处的
键入:true
级别?

我当前的解决方法是:()

#键入:true
模块对象接口
def类;超级的;结束
结束
模块M
包含对象接口
德福
自我阶级
结束
结束

这实际上是两个bug!感谢您指出:

不在
内核的垫片中

我们永远不应该建议包含非
模块的内容

供我参考,实际的代码在Yast::I18n中-我正在运行0.4.4296。感谢您关于包含的错误。修正如下: