Class: RBS::Types::Union
- Inherits:
-
Object
- Object
- RBS::Types::Union
- Defined in:
- lib/rbs/types.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #each_type(&block) ⇒ Object
- #free_variables(set = Set.new) ⇒ Object
- #hash ⇒ Object
-
#initialize(types:, location:) ⇒ Union
constructor
A new instance of Union.
- #map_type(&block) ⇒ Object
- #map_type_name(&block) ⇒ Object
- #sub(s) ⇒ Object
- #to_json(state = _ = nil) ⇒ Object
- #to_s(level = 0) ⇒ Object
Constructor Details
#initialize(types:, location:) ⇒ Union
Returns a new instance of Union.
525 526 527 528 |
# File 'lib/rbs/types.rb', line 525 def initialize(types:, location:) @types = types @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
523 524 525 |
# File 'lib/rbs/types.rb', line 523 def location @location end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
522 523 524 |
# File 'lib/rbs/types.rb', line 522 def types @types end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
530 531 532 |
# File 'lib/rbs/types.rb', line 530 def ==(other) other.is_a?(Union) && other.types == types end |
#each_type(&block) ⇒ Object
565 566 567 568 569 570 571 |
# File 'lib/rbs/types.rb', line 565 def each_type(&block) if block types.each(&block) else enum_for :each_type end end |
#free_variables(set = Set.new) ⇒ Object
540 541 542 543 544 545 546 |
# File 'lib/rbs/types.rb', line 540 def free_variables(set = Set.new) set.tap do types.each do |type| type.free_variables set end end end |
#hash ⇒ Object
536 537 538 |
# File 'lib/rbs/types.rb', line 536 def hash self.class.hash ^ types.hash end |
#map_type(&block) ⇒ Object
573 574 575 576 577 578 579 |
# File 'lib/rbs/types.rb', line 573 def map_type(&block) if block Union.new(types: types.map(&block), location: location) else enum_for :map_type end end |
#map_type_name(&block) ⇒ Object
581 582 583 584 585 586 |
# File 'lib/rbs/types.rb', line 581 def map_type_name(&block) Union.new( types: types.map {|type| type.map_type_name(&block) }, location: location ) end |
#sub(s) ⇒ Object
552 553 554 555 |
# File 'lib/rbs/types.rb', line 552 def sub(s) self.class.new(types: types.map {|ty| ty.sub(s) }, location: location) end |
#to_json(state = _ = nil) ⇒ Object
548 549 550 |
# File 'lib/rbs/types.rb', line 548 def to_json(state = _ = nil) { class: :union, types: types, location: location }.to_json(state) end |
#to_s(level = 0) ⇒ Object
557 558 559 560 561 562 563 |
# File 'lib/rbs/types.rb', line 557 def to_s(level = 0) if level > 0 "(#{types.join(" | ")})" else types.join(" | ") end end |