Class: Erlectricity::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/erlectricity/matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, condition, block) ⇒ Matcher

Returns a new instance of Matcher.



6
7
8
9
10
# File 'lib/erlectricity/matcher.rb', line 6

def initialize(parent, condition, block)
  self.receiver = parent
  @block = block
  @condition = Condition.for(condition)
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/erlectricity/matcher.rb', line 3

def block
  @block
end

#conditionObject

Returns the value of attribute condition.



3
4
5
# File 'lib/erlectricity/matcher.rb', line 3

def condition
  @condition
end

#receiverObject

Returns the value of attribute receiver.



4
5
6
# File 'lib/erlectricity/matcher.rb', line 4

def receiver
  @receiver
end

Instance Method Details

#matches?(arg) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/erlectricity/matcher.rb', line 17

def matches?(arg)
  @condition.satisfies?(arg)
end

#run(arg) ⇒ Object



12
13
14
15
# File 'lib/erlectricity/matcher.rb', line 12

def run(arg)
  args = @condition.binding_for(arg)
  block.call(*args)
end