Class: MultiCase::DSL
- Inherits:
-
Object
- Object
- MultiCase::DSL
- Defined in:
- lib/multi_case/dsl.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(lhs, rhs) ⇒ DSL
constructor
A new instance of DSL.
-
#multi(from_to, &block) ⇒ Object
A single case to which @lhs & @rhs are matched against.
Constructor Details
#initialize(lhs, rhs) ⇒ DSL
Returns a new instance of DSL.
6 7 8 9 10 11 |
# File 'lib/multi_case/dsl.rb', line 6 def initialize(lhs, rhs) @lhs = lhs @rhs = rhs @result = nil end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
13 14 15 |
# File 'lib/multi_case/dsl.rb', line 13 def result @result end |
Instance Method Details
#multi(from_to, &block) ⇒ Object
A single case to which @lhs & @rhs are matched against
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/multi_case/dsl.rb', line 22 def multi(from_to, &block) from = from_to.keys.flatten(1) from = [@lhs] if from.empty? # catch-all on empty array to = from_to.values.flatten(1) to = [@rhs] if to.empty? if from.product(to).map(&method(:param_equal)).any? @result ||= block.call end end |