Class: RBS::MethodType
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rbs/method_type.rb |
Class Method Summary
Instance Attribute Summary
- #block readonly
- #location readonly
- #type readonly
- #type_params readonly
Instance Method Summary
Constructor Details
.new(type_params:, type:, block:, location:) ⇒ MethodType
# File 'lib/rbs/method_type.rb', line 8
def initialize(type_params:, type:, block:, location:) @type_params = type_params @type = type @block = block @location = location end
Instance Attribute Details
#block (readonly)
[ GitHub ]# File 'lib/rbs/method_type.rb', line 5
attr_reader :block
#location (readonly)
[ GitHub ]# File 'lib/rbs/method_type.rb', line 6
attr_reader :location
#type (readonly)
[ GitHub ]# File 'lib/rbs/method_type.rb', line 4
attr_reader :type
#type_params (readonly)
[ GitHub ]# File 'lib/rbs/method_type.rb', line 3
attr_reader :type_params
Instance Method Details
#==(other)
[ GitHub ]# File 'lib/rbs/method_type.rb', line 15
def ==(other) other.is_a?(MethodType) && other.type_params == type_params && other.type == type && other.block == block end
#each_type(&block)
[ GitHub ]#free_variables(set = Set.new)
[ GitHub ]# File 'lib/rbs/method_type.rb', line 48
def free_variables(set = Set.new) type.free_variables(set) block&.type&.free_variables(set) set.subtract(type_params) end
#map_type(&block)
[ GitHub ]#sub(s)
[ GitHub ]# File 'lib/rbs/method_type.rb', line 31
def sub(s) s.without(*type_params).yield_self do |sub| map_type do |ty| ty.sub(sub) end end end
#to_json(state = _ = nil)
[ GitHub ]# File 'lib/rbs/method_type.rb', line 22
def to_json(state = _ = nil) { type_params: type_params, type: type, block: block, location: location }.to_json(state) end
#to_s
[ GitHub ]# File 'lib/rbs/method_type.rb', line 76
def to_s s = case when (b = block) && b.required "(#{type.param_to_s}) { (#{b.type.param_to_s}) -> #{b.type.return_to_s} } -> #{type.return_to_s}" when b = block "(#{type.param_to_s}) ?{ (#{b.type.param_to_s}) -> #{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
#update(type_params: self.type_params, type: self.type, block: self.block, location: self.location)
[ GitHub ]# File 'lib/rbs/method_type.rb', line 39
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