123456789_123456789_123456789_123456789_123456789_

Class: PowerAssert::SafeInspectable

Relationships & Source Files
Inherits: Object
Defined in: lib/power_assert.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(value) ⇒ SafeInspectable

[ GitHub ]

  
# File 'lib/power_assert.rb', line 62

def initialize(value)
  @value = value
end

Instance Method Details

#inspect

[ GitHub ]

  
# File 'lib/power_assert.rb', line 66

def inspect
  inspected = @value.inspect
  if Encoding.compatible?(Encoding.default_external, inspected)
    inspected
  else
    begin
      "#{inspected.encode(Encoding.default_external)}(#{inspected.encoding})"
    rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
      inspected.force_encoding(Encoding.default_external)
    end
  end
rescue => e
  "InspectionFailure: #{e.class}: #{e.message.each_line.first}"
end