class RBS::MethodType
Attributes
block
[R]
Types::Block?
location
[R]
loc?
type
[R]
Types::function
type_params
[R]
Array[AST::TypeParam]
Public Class Methods
(type_params: Array[AST::TypeParam], type: Types::function, block: Types::Block?, location: loc?) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 10 def initialize(type_params:, type:, block:, location:) @type_params = type_params @type = type @block = block @location = location end
Public Instance Methods
(untyped other) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 17 def ==(other) other.is_a?(MethodType) && other.type_params == type_params && other.type == type && other.block == block end
() { (Types::t) → void } → void
() → Enumerator[Types::t, void]
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 86 def each_type(&block) if block type.each_type(&block) self.block&.yield_self do |b| b.type.each_type(&block) if b.self_type yield b.self_type end end else enum_for :each_type end end
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 59 def free_variables(set = Set.new) type.free_variables(set) block&.type&.free_variables(set) set.subtract(type_param_names) end
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 127 def has_classish_type? each_type.any? {|type| type.has_classish_type? } end
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 123 def has_self_type? each_type.any? {|type| type.has_self_type? } end
() { (Types::t) → Types::t } → MethodType
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 65 def map_type(&block) self.class.new( type_params: type_params, type: type.map_type(&block), block: self.block&.map_type(&block), location: location ) end
Apply the mapping included in the MethodType.
Note that type bound in generics parameter is not handled by this method. You may want to use map_type_bound explicitly, or sub for simple substitution.
() { (Types::t) → Types::t } → MethodType
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 74 def map_type_bound(&block) if type_params.empty? self else self.update( type_params: type_params.map {|param| param.map_type(&block) } ) end end
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 33 def sub(s) sub = s.without(*type_param_names) return self if sub.empty? self.class.new( type_params: type_params.map do |param| param.map_type do |bound| bound.map_type {|ty| ty.sub(sub) } end end, type: type.sub(sub), block: block&.sub(sub), location: location ) end
Substitute type variables to some types. Takes care of type parameter bounds.
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 24 def to_json(state = nil) { type_params: type_params, type: type, block: block, location: location }.to_json(state) end
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 100 def to_s block_self_binding = Types::SelfTypeBindingHelper.self_type_binding_to_s(block&.self_type) s = case when (b = block) && b.required "(#{type.param_to_s}) { (#{b.type.param_to_s}) #{block_self_binding}-> #{b.type.return_to_s} } -> #{type.return_to_s}" when b = block "(#{type.param_to_s}) ?{ (#{b.type.param_to_s}) #{block_self_binding}-> #{b.type.return_to_s} } -> #{type.return_to_s}" else "(#{type.param_to_s}) -> #{type.return_to_s}" end if type_params.empty? s else "[#{type_params.join(", ")}] #{s}" end end
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 119 def type_param_names type_params.map(&:name) end
(?type_params: Array[AST::TypeParam], ?type: Types::function, ?block: Types::Block?, ?location: loc?) → MethodType
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 50 def update(type_params: self.type_params, type: self.type, block: self.block, location: self.location) self.class.new( type_params: type_params, type: type, block: block, location: location ) end
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/method_type.rb, line 131 def with_nonreturn_void? if type.with_nonreturn_void? # steep:ignore DeprecatedReference true else if block = block() block.type.with_nonreturn_void? || # steep:ignore DeprecatedReference block.self_type&.with_nonreturn_void? || # steep:ignore DeprecatedReference false else false end end end