Class: PatternMatching::Bindings
- Inherits:
- BasicObject
- Defined in:
- lib/pattern_matching/bindings.rb
Overview
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.
Defined Under Namespace
Classes: BoundValue
Instance Method Summary collapse
-
#initialize ⇒ Bindings
constructor
A new instance of Bindings.
-
#method_missing(msg) ⇒ Object
Hello darkness, my old friend.
Constructor Details
#initialize ⇒ Bindings
Returns a new instance of Bindings.
11 12 13 14 15 |
# File 'lib/pattern_matching/bindings.rb', line 11 def initialize @bindings = ::Hash.new do |hash, key| ::PatternMatching::Bindings::BoundValue.new(hash, key) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(msg) ⇒ Object
Hello darkness, my old friend.
19 20 21 |
# File 'lib/pattern_matching/bindings.rb', line 19 def method_missing(msg, *) @bindings[msg] end |