lib/amp/support/support.rb
##
# Splits on newlines only, removing extra blank line at end if there is one.
# This is how mercurial does it and i'm sticking to it. This method is evil.
# DON'T USE IT.
Splits on newlines only, removing extra blank line at end if there is one.
This is how mercurial does it and i'm sticking to it. This method is evil.
DON'T USE IT.
Splits on newlines only removing extra blank line at end if there is one . This is how mercurial does it and i ' m sticking to it . This method is evil . DON ' T USE IT .
def split_newlines(add_newlines=true)
    return [] if self.empty?
    lines = self.split("\n").map {|l| l + (add_newlines ? "\n" : "") } 
    return lines if lines.size == 1
    if (add_newlines && lines.last == "\n") || (!add_newlines && lines.last.empty?)
      lines.pop 
    else
      lines[-1] = lines[-1][0..-2] if lines[-1][-1,1] == "\n"
    end
    lines
  end
def split_newlines ( add_newlines = true ) return [ ] if self . empty? lines = self . split ( "\n" ) . map { | l | l + ( add_newlines ? "\n" : "" ) } return lines if lines . size == 1 if ( add_newlines && lines . last == "\n" ) || ( ! add_newlines && lines . last . empty? ) lines . pop else lines [ - 1 ] = lines [ - 1 ] [ 0 .. - 2 ] if lines [ - 1 ] [ - 1 , 1 ] == "\n" end lines end
Splits on newlines only, removing extra blank line at end if there is one.
Splits on newlines only removing extra blank line at end if there is one .
add_newlines
<not_specific>