Class: Qo::Branches::WhenBranch

Inherits:
Branch
  • Object
show all
Defined in:
lib/qo/branches/when_branch.rb

Overview

Since:

  • 1.0.0

Constant Summary

Constants inherited from Branch

Branch::UNMATCHED

Instance Attribute Summary

Attributes inherited from Branch

#name

Instance Method Summary collapse

Methods inherited from Branch

create, #create_matcher, #default?

Constructor Details

#initialize(destructure: false) ⇒ WhenBranch

The traditional pattern matching branch, based off of when from Ruby's case statement:

Qo.case(1) { |m|
  m.when(Integer) { |v| v + 2 }
}
# => 3

Author:

  • baweaver

Since:

  • 1.0.0



16
17
18
# File 'lib/qo/branches/when_branch.rb', line 16

def initialize(destructure: false)
  super(name: 'when', destructure: destructure, default: false)
end