Class: Lookout::Encode
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
-
#call ⇒ String
(also: #to_s)
An UTF-8-encoded String representation of the object.
Instance Method Details
#call ⇒ String Also known as: to_s
Returns 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 |