Class: String

Inherits:
Object show all
Defined in:
lib/core_ext/string.rb

Overview

Reopen the core String class to represent #inspect_lit.

Instance Method Summary collapse

Instance Method Details

#inspect_litString

Formats self to look like a String literal so that object type will be inherently obvious when inspected.

Examples:

"test".inspect_lit  # => "\"test\"" (i.e. '"test"')
"1".inspect_lit     # => "\"1\""    (i.e. '"1"')
"12.3".inspect_lit  # => "\"12.3\"" (i.e. '"12.3"')

Returns:

  • (String)

    a String-literal representation of this object



14
15
16
# File 'lib/core_ext/string.rb', line 14

def inspect_lit
  %("#{self}")
end