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_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.
465 466 467 468 |
# File 'lib/rbs/types.rb', line 465 def initialize(type:, location:) @type = type @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
463 464 465 |
# File 'lib/rbs/types.rb', line 463 def location @location end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
462 463 464 |
# File 'lib/rbs/types.rb', line 462 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
470 471 472 |
# File 'lib/rbs/types.rb', line 470 def ==(other) other.is_a?(Optional) && other.type == type end |
#each_type ⇒ Object
504 505 506 507 508 509 510 |
# File 'lib/rbs/types.rb', line 504 def each_type if block_given? yield type else enum_for :each_type end end |
#free_variables(set = Set.new) ⇒ Object
480 481 482 |
# File 'lib/rbs/types.rb', line 480 def free_variables(set = Set.new) type.free_variables(set) end |
#hash ⇒ Object
476 477 478 |
# File 'lib/rbs/types.rb', line 476 def hash self.class.hash ^ type.hash end |
#map_type_name(&block) ⇒ Object
512 513 514 515 516 517 |
# File 'lib/rbs/types.rb', line 512 def map_type_name(&block) Optional.new( type: type.map_type_name(&block), location: location ) end |
#sub(s) ⇒ Object
488 489 490 |
# File 'lib/rbs/types.rb', line 488 def sub(s) self.class.new(type: type.sub(s), location: location) end |
#to_json(state = _ = nil) ⇒ Object
484 485 486 |
# File 'lib/rbs/types.rb', line 484 def to_json(state = _ = nil) { class: :optional, type: type, location: location }.to_json(state) end |