Class: RBS::Types::Optional
- Inherits:
-
Object
- Object
- RBS::Types::Optional
- Defined in:
- lib/rbs/types.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #each_type ⇒ Object
- #free_variables(set = Set.new) ⇒ Object
- #hash ⇒ Object
-
#initialize(type:, location:) ⇒ Optional
constructor
A new instance of Optional.
- #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(type:, location:) ⇒ Optional
Returns a new instance of Optional.
519 520 521 522 |
# File 'lib/rbs/types.rb', line 519 def initialize(type:, location:) @type = type @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 |
#type ⇒ Object (readonly)
Returns the value of attribute type.
516 517 518 |
# File 'lib/rbs/types.rb', line 516 def type @type 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?(Optional) && other.type == type end |
#each_type ⇒ Object
558 559 560 561 562 563 564 |
# File 'lib/rbs/types.rb', line 558 def each_type if block_given? yield type else enum_for :each_type end end |
#free_variables(set = Set.new) ⇒ Object
534 535 536 |
# File 'lib/rbs/types.rb', line 534 def free_variables(set = Set.new) type.free_variables(set) end |
#hash ⇒ Object
530 531 532 |
# File 'lib/rbs/types.rb', line 530 def hash self.class.hash ^ type.hash end |
#map_type(&block) ⇒ Object
573 574 575 576 577 578 579 580 581 582 |
# File 'lib/rbs/types.rb', line 573 def map_type(&block) if block Optional.new( type: yield(type), location: location ) else enum_for :map_type end end |
#map_type_name(&block) ⇒ Object
566 567 568 569 570 571 |
# File 'lib/rbs/types.rb', line 566 def map_type_name(&block) Optional.new( type: type.map_type_name(&block), location: location ) end |
#sub(s) ⇒ Object
542 543 544 |
# File 'lib/rbs/types.rb', line 542 def sub(s) self.class.new(type: type.sub(s), location: location) end |
#to_json(state = _ = nil) ⇒ Object
538 539 540 |
# File 'lib/rbs/types.rb', line 538 def to_json(state = _ = nil) { class: :optional, type: type, location: location }.to_json(state) end |