class PatternMatching::Bindings::BoundValue
The interesting work of Bindings
happens in this class.
Allows setting up guards via the >> oprator.
If guards pass, or no guards have been added to a BoundValue
, then comparing via == or === with that BoundValue
will always return true, and will save the compared-to value in the hash, presumably provided by an instance of the Bindings
class.
Public Class Methods
new(bindings, name)
click to toggle source
# File lib/pattern_matching/bindings.rb, line 34 def initialize(bindings, name) @bindings = bindings @name = name @guards = [] end
Public Instance Methods
==(other)
click to toggle source
# File lib/pattern_matching/bindings.rb, line 40 def ==(other) return false unless @guards.all? { |g| g === other } @bindings[@name] = other true end
===(other)
click to toggle source
# File lib/pattern_matching/bindings.rb, line 46 def ===(other) return false unless @guards.all? { |g| g === other } @bindings[@name] = other true end
>>(guard)
click to toggle source
# File lib/pattern_matching/bindings.rb, line 52 def >>(guard) @guards << guard self end