How can I preserve / maintain consecutive newlines in Ruby here-document?


I wonder how can I preserve consecutive newline characters with Ruby here-document? In my program all of them are collapsed to one newline. For example:

s=<<END 1 2 3 4 END

evaluates to:


However I would like to preserve the consecutive newlines when for example formatting a BBcode document a letter or something similar.


That looks like a bug to me. Have you tried a multiline %q?

s=%q(1 2 3 4 )


  • JScrollPane vertical scrollbar too wide
  • Full Clickable Accordion in Bootstrap
  • Slickgrid grouping expand/collapse strange behaviour
  • Hadoop custom split of TextFile
  • Read CSV file with embedded newlines
  • Reading a line from file in C, dynamically
  • Python EOF error when reading input
  • Using Unique Key in SQL with or without try/catch as a valid way to verify integrity of data
  • ANTLR generating empty conditions
  • python subprocess.stdout.readline doesn't
  • Image loaded from Isolated storage are not binding at all
  • My PHP newline beginner code isn't going to a new line. Little help?
  • How can I overwrite a file in UWP?
  • Quoted parameter expansion with quoted modifier in Bash
  • Find row numbers in a binary array with a certain code
  • JSeperator in JToolBar moves the components to right end
  • How does one get div content line-by-line with Javascript?
  • Text similarity analysis (Excel)
  • TabBarController: Orienting views in different orientations
  • Standard way for writing a debug mode in C++
  • Complex python3 csv scraper
  • How to add new index numbers to the upsampled data while preserving the orginal indices one
  • Collapsible Sankey Diagram - D3
  • Catching exception and throwing the same?
  • how do i write assembly code from c#?
  • Memory error in python- how to use more memory
  • SAXReader not re-ecape characters
  • Differences in dis-assembled C code of GCC and Borland?
  • Chart.js Multiple dataset
  • How do I get HTML corresponding to current DOM tree?
  • JQuery Internet Explorer and ajaxstop
  • JSON response opens as a file, but I can't access it with JavaScript
  • Algorithm for a smudge tool?
  • Change an a tag attribute in JavaScript based on screen width
  • 0x202A in filename: Why?
  • Python: how to group similar lists together in a list of lists?
  • Checking variable from a different class in C#
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal