class String

Public Instance Methods

^(code)
Alias for: ansi_escape
ansi_escape(code) click to toggle source
# File library/majic/ansi_escape.rb, line 4
def ansi_escape code
  ANSIEscape[code] + self + ANSIEscape[]
end
Also aliased as: ^
ellipsize(length = 9) click to toggle source
# File library/majic/core_extensions/string.rb, line 9
def ellipsize length = 9
  return self if self.size <= length

  remainder = length - 3
  offset = remainder / 2
  (self[0, offset + (remainder.odd? ? 1 : 0)].to_s + '…' + self[-offset, offset].to_s)[0, length].to_s
end
truncate!(length, position = :middle) click to toggle source
# File library/majic/core_extensions/string.rb, line 2
def truncate! length, position = :middle
  case position
  when :middle
    replace ellipsize length
  end
end