lib/tapioca/rbi_ext/model.rb in tapioca-0.5.6 vs lib/tapioca/rbi_ext/model.rb in tapioca-0.6.0
- old
+ new
@@ -65,26 +65,28 @@
else
raise "unexpected type: #{constant_name} is a #{instance.class}"
end
end
- sig { params(name: String, block: T.nilable(T.proc.params(scope: Scope).void)).void }
+ sig { params(name: String, block: T.nilable(T.proc.params(scope: Scope).void)).returns(Scope) }
def create_module(name, &block)
- node = create_node(RBI::Module.new(name))
- block&.call(T.cast(node, RBI::Scope))
+ T.cast(create_node(RBI::Module.new(name)), RBI::Scope).tap do |node|
+ block&.call(node)
+ end
end
sig do
params(
name: String,
superclass_name: T.nilable(String),
block: T.nilable(T.proc.params(scope: RBI::Scope).void)
- ).void
+ ).returns(Scope)
end
def create_class(name, superclass_name: nil, &block)
- node = create_node(RBI::Class.new(name, superclass_name: superclass_name))
- block&.call(T.cast(node, RBI::Scope))
+ T.cast(create_node(RBI::Class.new(name, superclass_name: superclass_name)), RBI::Scope).tap do |node|
+ block&.call(node)
+ end
end
sig { params(name: String, value: String).void }
def create_constant(name, value:)
create_node(RBI::Const.new(name, value))
@@ -113,17 +115,18 @@
sig do
params(
name: String,
parameters: T::Array[TypedParam],
return_type: String,
- class_method: T::Boolean
+ class_method: T::Boolean,
+ visibility: RBI::Visibility
).void
end
- def create_method(name, parameters: [], return_type: "T.untyped", class_method: false)
+ def create_method(name, parameters: [], return_type: "T.untyped", class_method: false, visibility: RBI::Public.new)
return unless valid_method_name?(name)
sig = RBI::Sig.new(return_type: return_type)
- method = RBI::Method.new(name, sigs: [sig], is_singleton: class_method)
+ method = RBI::Method.new(name, sigs: [sig], is_singleton: class_method, visibility: visibility)
parameters.each do |param|
method << param.param
sig << RBI::SigParam.new(param.param.name, param.type)
end
self << method