class String

Public Instance Methods

escape_heredoc() click to toggle source
# File lib/util/utilities.rb, line 2
def escape_heredoc
  this = dup
  lines = this.split(/\r\n|\r|\n/).select { |line| line.size > 0 }
  levels = lines.map do |line|
    match = line.match(/^( +)[^ ]+/)
    match ? match[1].size : 0
  end
  level = levels.min
  this.gsub!(/^#{' ' * level}/, '') if level > 0
  this
end