Class: SwitchException::ExceptionSwitch

Inherits:
Object
  • Object
show all
Defined in:
lib/switch-exception.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#handledObject (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.message =~ re }
    @handled = true
    block ? block.call(@exception) : nil
  end
end