Class: Rigor::Type::BoundMethod
- Inherits:
-
Object
- Object
- Rigor::Type::BoundMethod
- Defined in:
- lib/rigor/type/bound_method.rb
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
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#receiver_type ⇒ Object
readonly
Returns the value of attribute receiver_type.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #accepts(other, mode: :gradual) ⇒ Object
- #bot ⇒ Object
- #describe(verbosity = :short) ⇒ Object
- #dynamic ⇒ Object
- #erase_to_rbs ⇒ Object
- #hash ⇒ Object
-
#initialize(receiver_type:, method_name:) ⇒ BoundMethod
constructor
A new instance of BoundMethod.
- #inspect ⇒ Object
- #top ⇒ Object
Constructor Details
#initialize(receiver_type:, method_name:) ⇒ BoundMethod
Returns a new instance of BoundMethod.
30 31 32 33 34 35 36 37 |
# File 'lib/rigor/type/bound_method.rb', line 30 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_name ⇒ Object (readonly)
Returns the value of attribute method_name.
28 29 30 |
# File 'lib/rigor/type/bound_method.rb', line 28 def method_name @method_name end |
#receiver_type ⇒ Object (readonly)
Returns the value of attribute receiver_type.
28 29 30 |
# File 'lib/rigor/type/bound_method.rb', line 28 def receiver_type @receiver_type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
63 64 65 66 67 |
# File 'lib/rigor/type/bound_method.rb', line 63 def ==(other) other.is_a?(BoundMethod) && receiver_type == other.receiver_type && method_name == other.method_name end |
#accepts(other, mode: :gradual) ⇒ Object
59 60 61 |
# File 'lib/rigor/type/bound_method.rb', line 59 def accepts(other, mode: :gradual) Inference::Acceptance.accepts(self, other, mode: mode) end |
#describe(verbosity = :short) ⇒ Object
39 40 41 |
# File 'lib/rigor/type/bound_method.rb', line 39 def describe(verbosity = :short) "Method<#{receiver_type.describe(verbosity)}##{method_name}>" end |
#dynamic ⇒ Object
55 56 57 |
# File 'lib/rigor/type/bound_method.rb', line 55 def dynamic Trinary.no end |
#erase_to_rbs ⇒ Object
43 44 45 |
# File 'lib/rigor/type/bound_method.rb', line 43 def erase_to_rbs "Method" end |
#hash ⇒ Object
70 71 72 |
# File 'lib/rigor/type/bound_method.rb', line 70 def hash [BoundMethod, receiver_type, method_name].hash end |
#inspect ⇒ Object
74 75 76 |
# File 'lib/rigor/type/bound_method.rb', line 74 def inspect "#<Rigor::Type::BoundMethod #{describe(:short)}>" end |