Working with multiline strings in Ruby used to result in very odd looking code because heredocs required that you shift all of the string code so it was flush against the left hand side of the file. However, with modern versions of Ruby you are now able to utilize the squiggly heredoc syntax, which allows you to indent multiline strings in a file.
Refactor a multiline string in Ruby so that it can be indented.
Given a multiline string, stored in a Ruby Heredoc, refactor it so that you can indent the string instead of having it flushed to the left-hand side of the file.
Standard Heredoc Example
<<~EOL Some words in a heredoc EOL # Results in: Some words in a heredoc # Notice the spaces on the left hand side of the text
Some words in a heredoc
Real World Usage
Working with multiline strings in Ruby used to result in some very odd looking code. Because of fact that heredocs are parsed ‘as is’, it means that you had to place all of the strings all the way to the left of the file. More modern versions of Ruby allow you to indent multiline strings so they can match the rest of the code styles.
Can be found on the solutions branch on github.