Class: RBS::Types::Intersection
- Inherits:
-
Object
- Object
- RBS::Types::Intersection
- 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:) ⇒ Intersection
constructor
A new instance of Intersection.
- #map_type(&block) ⇒ Object
- #sub(s) ⇒ Object
- #to_json(*a) ⇒ Object
- #to_s(level = 0) ⇒ Object
Constructor Details
#initialize(types:, location:) ⇒ Intersection
Returns a new instance of Intersection.
519 520 521 522 |
# File 'lib/rbs/types.rb', line 519 def initialize(types:, location:) @types = types @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
517 518 519 |
# File 'lib/rbs/types.rb', line 517 def location @location end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
516 517 518 |
# File 'lib/rbs/types.rb', line 516 def types @types end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
524 525 526 |
# File 'lib/rbs/types.rb', line 524 def ==(other) other.is_a?(Intersection) && other.types == types end |
#each_type(&block) ⇒ Object
560 561 562 563 564 565 566 |
# File 'lib/rbs/types.rb', line 560 def each_type(&block) if block_given? types.each(&block) else enum_for :each_type end end |
#free_variables(set = Set.new) ⇒ Object
534 535 536 537 538 539 540 |
# File 'lib/rbs/types.rb', line 534 def free_variables(set = Set.new) set.tap do types.each do |type| type.free_variables set end end end |
#hash ⇒ Object
530 531 532 |
# File 'lib/rbs/types.rb', line 530 def hash self.class.hash ^ types.hash end |
#map_type(&block) ⇒ Object
568 569 570 571 572 573 574 |
# File 'lib/rbs/types.rb', line 568 def map_type(&block) if block_given? Intersection.new(types: types.map(&block), location: location) else enum_for :map_type end end |
#sub(s) ⇒ Object
546 547 548 549 |
# File 'lib/rbs/types.rb', line 546 def sub(s) self.class.new(types: types.map {|ty| ty.sub(s) }, location: location) end |
#to_json(*a) ⇒ Object
542 543 544 |
# File 'lib/rbs/types.rb', line 542 def to_json(*a) { class: :intersection, types: types, location: location }.to_json(*a) end |
#to_s(level = 0) ⇒ Object
551 552 553 554 555 556 557 558 |
# File 'lib/rbs/types.rb', line 551 def to_s(level = 0) strs = types.map {|ty| ty.to_s(2) } if level > 0 "(#{strs.join(" & ")})" else strs.join(" & ") end end |