Method: Hanami::Utils::Kernel.inspect_type_error

Defined in:
lib/hanami/utils/kernel.rb

.inspect_type_error(arg) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the most useful type error possible

If the object does not respond_to?(:inspect), we return the class, else we return nil. In all cases, this method is tightly bound to callers, as this method appends the required space to make the error message look good.

Since:

  • 0.4.3

[View source]

1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
# File 'lib/hanami/utils/kernel.rb', line 1046

def self.inspect_type_error(arg)
  "#{arg.respond_to?(:inspect) ? arg.inspect : arg.to_s} "
rescue NoMethodError
  # missing the #respond_to? method, fall back to returning the class' name
  begin
    "#{arg.class.name} instance "
  rescue NoMethodError
    # missing the #class method, can't fall back to anything better than nothing
    # Callers will have to guess from their code
    nil
  end
end