Class: Either::Match

Inherits:
Object
  • Object
show all
Defined in:
lib/either/match.rb

Defined Under Namespace

Classes: Evaluation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMatch

Returns a new instance of Match.



4
5
6
7
# File 'lib/either/match.rb', line 4

def initialize
  @lefts = []
  @rights = []
end

Instance Attribute Details

#leftsObject (readonly)

Returns the value of attribute lefts.



21
22
23
# File 'lib/either/match.rb', line 21

def lefts
  @lefts
end

#rightsObject (readonly)

Returns the value of attribute rights.



21
22
23
# File 'lib/either/match.rb', line 21

def rights
  @rights
end

Instance Method Details

#evaluate(either) ⇒ Object



17
18
19
# File 'lib/either/match.rb', line 17

def evaluate(either)
  Evaluation.new(self, either).result
end

#left(pattern = always, &block) ⇒ Object



9
10
11
# File 'lib/either/match.rb', line 9

def left pattern=always, &block
  @lefts << [(lambify pattern), block]
end

#right(pattern = always, &block) ⇒ Object



13
14
15
# File 'lib/either/match.rb', line 13

def right pattern=always, &block
  @rights << [(lambify pattern), block]
end