class String

Public Instance Methods

indent(offset) click to toggle source
# File lib/bashly/extensions/string.rb, line 6
def indent(offset)
  return self unless offset > 0
  split("\n").indent(offset).join("\n")
end
lint() click to toggle source
# File lib/bashly/extensions/string.rb, line 26
def lint
  gsub(/\n{2,}/, "\n\n")
end
sanitize_for_print() click to toggle source
# File lib/bashly/extensions/string.rb, line 2
def sanitize_for_print
  gsub("\n", "\\n").gsub("\"", "\\\"")
end
to_underscore() click to toggle source
# File lib/bashly/extensions/string.rb, line 11
def to_underscore
  gsub(/(.)([A-Z])/,'\1_\2').gsub(/[\- ]/, '_').downcase
end
wrap(length = 80) click to toggle source
# File lib/bashly/extensions/string.rb, line 15
def wrap(length = 80)
  strip!
  split("\n").collect! do |line|
    if line.length > length
      line.gsub(/(.{1,#{length}})(\s+|$)/, "\\1\n").rstrip
    else
      line
    end
  end * "\n"
end