class PatternMatching::BindingsSet

Constants

REMOVABLE_OBJECT_METHODS

For reasons I have yet to determine, implementing BindingsSet as a subclass of BasicObject has caused stack overflow issues. So the current workaround is to just remove everything we possibly can from this class at load time via the very hamfisted Module#undef_method.

Public Class Methods

new() click to toggle source
# File lib/pattern_matching/bindings_set.rb, line 63
def initialize
  @bindings = {}
end

Public Instance Methods

_clear_bindings!(caller_label) click to toggle source

Used internally as a hacky hook into auto-bindings with the B constant, when enabled. See documentation for automatic bindings.

# File lib/pattern_matching/bindings_set.rb, line 79
def _clear_bindings!(caller_label)
  @bindings.delete(caller_label)
end
method_missing(msg, *) click to toggle source

Based on the caller's method name (obviously not an universally-optimal choice), cache a Bindings object and forward all messages there.

# File lib/pattern_matching/bindings_set.rb, line 70
def method_missing(msg, *)
  caller_label = caller_locations(1,1)[0].label
  @bindings[caller_label] ||= PatternMatching::Bindings.new
  @bindings[caller_label].send(msg)
end