Exception: PowerConverter::ConversionError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/power_converter.rb

Overview

When you tried to convert something and it just won’t convert, this is a great exception to raise.

Instance Method Summary collapse

Constructor Details

#initialize(value, options) ⇒ ConversionError

Do or do not. There is no try.

Examples:

raise ConversionError.new(:boolean, [:hello, :world])

Parameters:

  • value (Object)
  • options (Hash)

Options Hash (options):

  • :to (Symbol)

    what did we just attempt to convert?

  • :scope (Symbol)

    is there a scope related to this conversion attempt?



47
48
49
50
51
# File 'lib/power_converter.rb', line 47

def initialize(value, options)
  named_converter = options[:to]
  scope = options[:scope]
  super("Unable to convert #{value.inspect} to '#{named_converter}' (scope: #{scope.inspect}).")
end