Class: Rigor::Type::BoundMethod

Inherits:
Object
  • Object
show all
Includes:
AcceptanceRouter, PlainLattice, ValueSemantics
Defined in:
lib/rigor/type/bound_method.rb,
sig/rigor/type.rbs

Overview

A Method carrier that tracks the bound (receiver, name) pair.

Ruby's Object#method(name) returns a Method instance whose later .call / .() / [] dispatches name on the original receiver. The plain RBS Method nominal cannot carry that binding, so call sites on the resulting Method collapse to untyped — losing the per-method precision the original receiver supports.

BoundMethod keeps the binding so the dispatcher can substitute the original (receiver, name) dispatch at .call / .() / [] time. The carrier erases to Method at the RBS boundary so downstream RBS interop (e.g. passing the value into a method whose parameter is typed ::Method) stays compatible — the binding is only consulted when Rigor itself dispatches.

See lib/rigor/inference/method_dispatcher/method_folding.rb for the forward (Object#method(:sym)) and backward (BoundMethod#call) folding tiers that consume / produce this carrier.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ValueSemantics

included

Constructor Details

#initialize(receiver_type:, method_name:) ⇒ BoundMethod

Returns a new instance of BoundMethod.

Parameters:

  • receiver_type: (Type::t)
  • method_name: (Symbol)

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
# File 'lib/rigor/type/bound_method.rb', line 28

def initialize(receiver_type:, method_name:)
  raise ArgumentError, "receiver_type must not be nil" if receiver_type.nil?
  raise ArgumentError, "method_name must be a Symbol, got #{method_name.inspect}" unless method_name.is_a?(Symbol)

  @receiver_type = receiver_type
  @method_name = method_name
  freeze
end

Instance Attribute Details

#method_nameSymbol (readonly)

Returns the value of attribute method_name.

Returns:

  • (Symbol)


26
27
28
# File 'lib/rigor/type/bound_method.rb', line 26

def method_name
  @method_name
end

#receiver_typeType::t (readonly)

Returns the value of attribute receiver_type.

Returns:

  • (Type::t)


26
27
28
# File 'lib/rigor/type/bound_method.rb', line 26

def receiver_type
  @receiver_type
end

Instance Method Details

#==Boolean

Parameters:

  • other (Object)

Returns:

  • (Boolean)


192
# File 'sig/rigor/type.rbs', line 192

def ==: (untyped other) -> bool

#acceptsAcceptsResult

Parameters:

  • other (Type::t)
  • mode: (accepts_mode)

Returns:



191
# File 'sig/rigor/type.rbs', line 191

def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult

#botTrinary

Returns:



189
# File 'sig/rigor/type.rbs', line 189

def bot: () -> Trinary

#describe(verbosity = :short) ⇒ String

Parameters:

  • verbosity (Symbol) (defaults to: :short)

Returns:

  • (String)


37
38
39
# File 'lib/rigor/type/bound_method.rb', line 37

def describe(verbosity = :short)
  "Method<#{receiver_type.describe(verbosity)}##{method_name}>"
end

#dynamicTrinary

Returns:



190
# File 'sig/rigor/type.rbs', line 190

def dynamic: () -> Trinary

#erase_to_rbsString

Returns:

  • (String)


41
42
43
# File 'lib/rigor/type/bound_method.rb', line 41

def erase_to_rbs
  "Method"
end

#hashInteger

Returns:

  • (Integer)


193
# File 'sig/rigor/type.rbs', line 193

def hash: () -> Integer

#inspectString

Returns:

  • (String)


53
54
55
# File 'lib/rigor/type/bound_method.rb', line 53

def inspect
  "#<Rigor::Type::BoundMethod #{describe(:short)}>"
end

#topTrinary

Returns:



188
# File 'sig/rigor/type.rbs', line 188

def top: () -> Trinary