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.
521 522 523 524 |
# File 'lib/rbs/types.rb', line 521 def initialize(type:, location:) @type = type @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
519 520 521 |
# File 'lib/rbs/types.rb', line 519 def location @location end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
518 519 520 |
# File 'lib/rbs/types.rb', line 518 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
526 527 528 |
# File 'lib/rbs/types.rb', line 526 def ==(other) other.is_a?(Optional) && other.type == type end |
#each_type ⇒ Object
560 561 562 563 564 565 566 |
# File 'lib/rbs/types.rb', line 560 def each_type if block_given? yield type else enum_for :each_type end end |
#free_variables(set = Set.new) ⇒ Object
536 537 538 |
# File 'lib/rbs/types.rb', line 536 def free_variables(set = Set.new) type.free_variables(set) end |
#hash ⇒ Object
532 533 534 |
# File 'lib/rbs/types.rb', line 532 def hash self.class.hash ^ type.hash end |
#map_type(&block) ⇒ Object
575 576 577 578 579 580 581 582 583 584 |
# File 'lib/rbs/types.rb', line 575 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
568 569 570 571 572 573 |
# File 'lib/rbs/types.rb', line 568 def map_type_name(&block) Optional.new( type: type.map_type_name(&block), location: location ) end |
#sub(s) ⇒ Object
544 545 546 |
# File 'lib/rbs/types.rb', line 544 def sub(s) self.class.new(type: type.sub(s), location: location) end |
#to_json(state = _ = nil) ⇒ Object
540 541 542 |
# File 'lib/rbs/types.rb', line 540 def to_json(state = _ = nil) { class: :optional, type: type, location: location }.to_json(state) end |