Class: Lookout::Encode

Inherits:
Object show all
Defined in:
lib/lookout-3.0/encode.rb

Overview

Encodes objects as UTF-8-encoded Strings. This is done by calling String with the object as the argument and then calling #encode on the result, if the result responds to it. This is primarily useful for compatibility between Ruby 1.8 and 1.9.

Instance Method Summary collapse

Instance Method Details

#callString Also known as: to_s

Returns An UTF-8-encoded String representation of the object.

Returns:

  • (String)

    An UTF-8-encoded String representation of the object



13
14
15
16
17
# File 'lib/lookout-3.0/encode.rb', line 13

def call
  string = String(object)
  return string unless (string.respond_to?(:encode) rescue true)
  string.encode('UTF-8')
end