Class: SwitchException::ExceptionSwitch
- Inherits:
-
Object
- Object
- SwitchException::ExceptionSwitch
- Defined in:
- lib/switch-exception.rb
Instance Attribute Summary collapse
-
#handled ⇒ Object
readonly
Returns the value of attribute handled.
Instance Method Summary collapse
-
#initialize(e) ⇒ ExceptionSwitch
constructor
A new instance of ExceptionSwitch.
- #on(*regexi, &block) ⇒ Object
Constructor Details
#initialize(e) ⇒ ExceptionSwitch
Returns a new instance of ExceptionSwitch.
14 15 16 17 |
# File 'lib/switch-exception.rb', line 14 def initialize(e) @exception = e @handled = false end |
Instance Attribute Details
#handled ⇒ Object (readonly)
Returns the value of attribute handled.
12 13 14 |
# File 'lib/switch-exception.rb', line 12 def handled @handled end |
Instance Method Details
#on(*regexi, &block) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/switch-exception.rb', line 19 def on(*regexi, &block) if @handled return elsif regexi.any? { |re| @exception. =~ re } @handled = true block ? block.call(@exception) : nil end end |