class Either::Match

Attributes

lefts[R]
rights[R]

Public Class Methods

new() click to toggle source
# File lib/either/match.rb, line 4
def initialize
  @lefts = []
  @rights = []
end

Public Instance Methods

evaluate(either) click to toggle source
# File lib/either/match.rb, line 17
def evaluate(either)
  Evaluation.new(self, either).result
end
left(pattern=always, &block) click to toggle source
# File lib/either/match.rb, line 9
def left pattern=always, &block
  @lefts << [(lambify pattern), block]
end
right(pattern=always, &block) click to toggle source
# File lib/either/match.rb, line 13
def right pattern=always, &block
  @rights << [(lambify pattern), block]
end

Private Instance Methods

always() click to toggle source
# File lib/either/match.rb, line 29
def always
  ->(x) { true }
end
lambify(pattern) click to toggle source
# File lib/either/match.rb, line 25
def lambify(pattern)
  pattern.is_a?(Proc) ? pattern : ->(x){ x == pattern }
end