Module: Expandable
- Included in:
- Hash
- Defined in:
- lib/core_ext.rb
Overview
Mixin for combining variations
{ a: :b }. #=> [{ a: :b }]
{ a: [:b, :c] }. #=> [{ a: :b }, { a: :c }]
{
a: [:b, :c],
d: [:e, :f],
}.
#=> [{ a: :b, d: :e }, {a: :b, d: :f}, { a: :c, d: :e }, { a: :c, d: :f }]
Instance Method Summary collapse
-
#expand ⇒ Array
Returns an array composed of all possible variation of the object by combining all the items of it’s array values.
Instance Method Details
#expand ⇒ Array
Returns an array composed of all possible variation of the object by combining all the items of it’s array values.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/core_ext.rb', line 17 def @expand_res = [{}] each do |key, value| case value when Array then (key) when Hash then (key) else @expand_res.map! { |hash| hash.merge(key => value) } end end @expand_res end |