Method: Lotus::Utils::Kernel.inspect_type_error

Defined in:
lib/lotus/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



1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
# File 'lib/lotus/utils/kernel.rb', line 1041

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