0

如何允许动态定义类的父类并通过 Sorbet 类型检查?

例如:


class A; end

class B < Object.const_get("A"); end

这是 Rails gem 的一部分,需要配置模型的基类,类似于Devise 配置父控制器类

运行时,srb tc返回错误:Superclasses must only contain constant literals https://srb.help/4002

或者,我尝试过暗示:

class A; end

class B < T.let(Object.const_get("A"), A); end

...这会导致类型检查错误,如Method some_method does not exist on T.class_of(B) https://srb.help/7003, 并srb rbi hidden-definitions引发此错误:

ruby/gems/2.7.0/gems/sorbet-runtime-0.5.6371/lib/types/private/casts.rb:23:in `cast': T.let: Expected type A, got type Class with value A (TypeError)
4

0 回答 0