Class: RBI::Type::Proc

Inherits:
Type
  • Object
show all
Defined in:
lib/rbi/type.rb

Overview

A proc type like T.proc.void.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProc

Returns a new instance of Proc.

Signature:

  • -> void



761
762
763
764
765
766
# File 'lib/rbi/type.rb', line 761

def initialize
  super
  @proc_params = {} #: Hash[Symbol, Type]
  @proc_returns = Type.void #: Type
  @proc_bind = nil #: Type?
end

Instance Attribute Details

#proc_bindObject (readonly)

Signature:

  • Type?



758
759
760
# File 'lib/rbi/type.rb', line 758

def proc_bind
  @proc_bind
end

#proc_paramsObject (readonly)

Signature:

  • Hash[Symbol, Type]



752
753
754
# File 'lib/rbi/type.rb', line 752

def proc_params
  @proc_params
end

#proc_returnsObject (readonly)

Signature:

  • Type



755
756
757
# File 'lib/rbi/type.rb', line 755

def proc_returns
  @proc_returns
end

Instance Method Details

#==(other) ⇒ Object

Signature:

  • (BasicObject other) -> bool



770
771
772
773
774
775
776
777
# File 'lib/rbi/type.rb', line 770

def ==(other)
  return false unless Proc === other
  return false unless @proc_params == other.proc_params
  return false unless @proc_returns == other.proc_returns
  return false unless @proc_bind == other.proc_bind

  true
end

#bind(type) ⇒ Object

Signature:

  • (untyped type) -> self



798
799
800
801
# File 'lib/rbi/type.rb', line 798

def bind(type)
  @proc_bind = type
  self
end

#normalizeObject

Signature:

  • -> Type



830
831
832
# File 'lib/rbi/type.rb', line 830

def normalize
  self
end

#params(**params) ⇒ Object

Signature:

  • (**Type params) -> self



780
781
782
783
# File 'lib/rbi/type.rb', line 780

def params(**params)
  @proc_params = params
  self
end

#returns(type) ⇒ Object

Signature:

  • (untyped type) -> self



786
787
788
789
# File 'lib/rbi/type.rb', line 786

def returns(type)
  @proc_returns = type
  self
end

#simplifyObject

Signature:

  • -> Type



836
837
838
# File 'lib/rbi/type.rb', line 836

def simplify
  self
end

#to_rbiObject

Signature:

  • -> String



805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
# File 'lib/rbi/type.rb', line 805

def to_rbi
  rbi = +"::T.proc"

  if @proc_bind
    rbi << ".bind(#{@proc_bind})"
  end

  unless @proc_params.empty?
    rbi << ".params("
    rbi << @proc_params.map { |name, type| "#{name}: #{type.to_rbi}" }.join(", ")
    rbi << ")"
  end

  rbi << case @proc_returns
  when Void
    ".void"
  else
    ".returns(#{@proc_returns})"
  end

  rbi
end

#voidObject

Signature:

  • -> self



792
793
794
795
# File 'lib/rbi/type.rb', line 792

def void
  @proc_returns = RBI::Type.void
  self
end