More Rails Features

Flashcard 1 of 8

Heredocs are a handy way of defining multi-line strings:

instructions = <<-INSTRUCTIONS
Here is a long set of instructions.

You've got to do a lot of things:

1. This thing.
2. That thing.
3. Even more
INSTRUCTIONS

One issue you might encounter is defining a heredoc in some code that is indented:

class Messages
  def self.welcome
    <<-WELCOME
This is the welcome message.

However, because it's a heredoc, we need to unindent it all the way out :(. 

Otherwise Ruby thinks the indentation we include is part of the string.
WELCOME
  end
end

How can we have our heredocs and maintain our usual indentation scheme?

Answer:

Reveal Answer