Class: DevelopWithPassion::Arrays::MutatorStep

Inherits:
Object
  • Object
show all
Defined in:
lib/developwithpassion_arrays/mutator_step.rb

Instance Method Summary collapse

Instance Method Details

#run_using(builder) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/developwithpassion_arrays/mutator_step.rb', line 4

def run_using(builder)
Module.new do
  builder.mutators.each do|mutator|
    define_method(mutator.name) do|value|
      array_var = instance_variable_get("@#{builder.name}")
      continue_add = true
      builder.criteria.each{|criteria| continue_add &= criteria.apply_to(value)}
      return unless continue_add
      array_var.push(value) unless mutator.block
      mutator.block.call(value) if mutator.block
    end
  end
end
end