Class: Steep::Interface::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/interface/method_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#optionalObject (readonly)

Returns the value of attribute optional.



533
534
535
# File 'lib/steep/interface/method_type.rb', line 533

def optional
  @optional
end

#typeObject (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

Returns:

  • (Boolean)


555
556
557
# File 'lib/steep/interface/method_type.rb', line 555

def closed?
  type.closed?
end

#free_variablesObject



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

Returns:

  • (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_optionalObject



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_sObject



570
571
572
# File 'lib/steep/interface/method_type.rb', line 570

def to_s
  "#{optional? ? "?" : ""}{ #{type.params} -> #{type.return_type} }"
end