class PatternMatching::Bindings

Taken nearly verbatim from the idea presented by Avdi Grimm in an episode of the fantastic Ruby Tapas series, including the use of the >> (right-shift) operator as a “guard” operator, as visually stands out compared to other define-able binary operators but it lacks idiomatic re-use the way that << (left-shift) does. It also feels a little bit like the \ guards used in Elixir, which I would have used, if I could find a way to have Ruby treat either \ or // as a binary operator.

Public Class Methods

new() click to toggle source
# File lib/pattern_matching/bindings.rb, line 11
def initialize
  @bindings = ::Hash.new do |hash, key|
    ::PatternMatching::Bindings::BoundValue.new(hash, key)
  end
end

Public Instance Methods

method_missing(msg, *) click to toggle source

Hello darkness, my old friend.

# File lib/pattern_matching/bindings.rb, line 19
def method_missing(msg, *)
  @bindings[msg]
end