Class: Steep::Interface::Block
- Inherits:
-
Object
- Object
- Steep::Interface::Block
- Defined in:
- lib/steep/interface/method_type.rb
Instance Attribute Summary collapse
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #closed? ⇒ Boolean
- #free_variables ⇒ Object
-
#initialize(type:, optional:) ⇒ Block
constructor
A new instance of Block.
- #map_type(&block) ⇒ Object
- #optional? ⇒ Boolean
- #subst(s) ⇒ Object
- #to_optional ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(type:, optional:) ⇒ Block
Returns a new instance of Block.
535 536 537 538 |
# File 'lib/steep/interface/method_type.rb', line 535 def initialize(type:, optional:) @type = type @optional = optional end |
Instance Attribute Details
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
533 534 535 |
# File 'lib/steep/interface/method_type.rb', line 533 def optional @optional end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
532 533 534 |
# File 'lib/steep/interface/method_type.rb', line 532 def type @type end |
Instance Method Details
#+(other) ⇒ Object
581 582 583 584 585 586 587 588 589 590 |
# File 'lib/steep/interface/method_type.rb', line 581 def +(other) optional = self.optional? || other.optional? type = AST::Types::Proc.new(params: self.type.params | other.type.params, return_type: AST::Types::Union.build(types: [self.type.return_type, other.type.return_type])) self.class.new( type: type, optional: optional ) end |
#==(other) ⇒ Object
551 552 553 |
# File 'lib/steep/interface/method_type.rb', line 551 def ==(other) other.is_a?(self.class) && other.type == type && other.optional == optional end |
#closed? ⇒ Boolean
555 556 557 |
# File 'lib/steep/interface/method_type.rb', line 555 def closed? type.closed? end |
#free_variables ⇒ Object
566 567 568 |
# File 'lib/steep/interface/method_type.rb', line 566 def free_variables type.free_variables end |
#map_type(&block) ⇒ Object
574 575 576 577 578 579 |
# File 'lib/steep/interface/method_type.rb', line 574 def map_type(&block) self.class.new( type: type.map_type(&block), optional: optional ) end |
#optional? ⇒ Boolean
540 541 542 |
# File 'lib/steep/interface/method_type.rb', line 540 def optional? @optional end |
#subst(s) ⇒ Object
559 560 561 562 563 564 |
# File 'lib/steep/interface/method_type.rb', line 559 def subst(s) self.class.new( type: type.subst(s), optional: optional ) end |
#to_optional ⇒ Object
544 545 546 547 548 549 |
# File 'lib/steep/interface/method_type.rb', line 544 def to_optional self.class.new( type: type, optional: true ) end |
#to_s ⇒ Object
570 571 572 |
# File 'lib/steep/interface/method_type.rb', line 570 def to_s "#{optional? ? "?" : ""}{ #{type.params} -> #{type.return_type} }" end |