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.
512 513 514 515 |
# File 'lib/rbs/types.rb', line 512 def initialize(types:, location:) @types = types @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
510 511 512 |
# File 'lib/rbs/types.rb', line 510 def location @location end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
509 510 511 |
# File 'lib/rbs/types.rb', line 509 def types @types end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
517 518 519 |
# File 'lib/rbs/types.rb', line 517 def ==(other) other.is_a?(Union) && other.types == types end |
#each_type(&block) ⇒ Object
552 553 554 555 556 557 558 |
# File 'lib/rbs/types.rb', line 552 def each_type(&block) if block types.each(&block) else enum_for :each_type end end |
#free_variables(set = Set.new) ⇒ Object
527 528 529 530 531 532 533 |
# File 'lib/rbs/types.rb', line 527 def free_variables(set = Set.new) set.tap do types.each do |type| type.free_variables set end end end |
#hash ⇒ Object
523 524 525 |
# File 'lib/rbs/types.rb', line 523 def hash self.class.hash ^ types.hash end |
#map_type(&block) ⇒ Object
560 561 562 563 564 565 566 |
# File 'lib/rbs/types.rb', line 560 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
568 569 570 571 572 573 |
# File 'lib/rbs/types.rb', line 568 def map_type_name(&block) Union.new( types: types.map {|type| type.map_type_name(&block) }, location: location ) end |
#sub(s) ⇒ Object
539 540 541 542 |
# File 'lib/rbs/types.rb', line 539 def sub(s) self.class.new(types: types.map {|ty| ty.sub(s) }, location: location) end |
#to_json(state = _ = nil) ⇒ Object
535 536 537 |
# File 'lib/rbs/types.rb', line 535 def to_json(state = _ = nil) { class: :union, types: types, location: location }.to_json(state) end |
#to_s(level = 0) ⇒ Object
544 545 546 547 548 549 550 |
# File 'lib/rbs/types.rb', line 544 def to_s(level = 0) if level > 0 "(#{types.join(" | ")})" else types.join(" | ") end end |