Class: Laborantin::ParameterHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/laborantin/core/parameter_hash.rb

Overview

A kind of Hash that can yields all possible configuration recursively. It should contains ParameterRange like definitions objects.

Instance Method Summary collapse

Instance Method Details

#each_config(remaining = self.keys, cfg = {}, &blk) ⇒ Object

Recursively yields all the possible configurations of parameters (a new hash). No order is supported on the recursion, and it is not planned to.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/laborantin/core/parameter_hash.rb', line 31

def each_config(remaining=self.keys, cfg={}, &blk)
  key = remaining.pop
  if key
    self[key].each do |val|
      cfg[key] = val
      each_config(remaining.dup, cfg, &blk)
    end
  else
    yield cfg
  end
end

#each_config_with_indexObject



43
44
45
46
47
48
49
# File 'lib/laborantin/core/parameter_hash.rb', line 43

def each_config_with_index
  idx = 0
  each_config do |cfg|
    yield cfg, idx
    idx += 1
  end
end