Skip to content

Instantly share code, notes, and snippets.

@rorcraft
Last active December 18, 2015 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rorcraft/5784318 to your computer and use it in GitHub Desktop.
Save rorcraft/5784318 to your computer and use it in GitHub Desktop.
ruby heredoc

Heredoc

  • auto indent
  • auto new line
<<GROCERY_LIST
  1. Salad mix 
  2. Strawberries 
  3. Cereal
  4. Milk grocery_list
GROCERY_LIST

=> ” 1. Salad mix.\n 2. Strawberries.\n 3. Cereal.\n 4. Milk.\n”
['Produce', '-------', <<PRODUCE, 'Dairy', '-----', <<DAIRY, '* Organic'].join("\n")
  1. Strawberries*
  2. Blueberries

PRODUCE
  1. Yogurt
  2. Milk*
  3. Cottage Cheese

DAIRY

=> "Produce\n-------\n  1. Strawberries*\n  2. Blueberries\n\n\nDairy\n-----\n  1. Yogurt\n  2. Milk*\n  3. Cottage Cheese\n\n\n* Organic"

Remove heredoc auto indent http://apidock.com/rails/String/strip_heredoc

['Produce', '-------', <<PRODUCE.strip_heredoc, 'Dairy', '-----', <<DAIRY.strip_heredoc, '* Organic'].join("\n")
  1. Strawberries*
  2. Blueberries

PRODUCE
  1. Yogurt
  2. Milk*
  3. Cottage Cheese

DAIRY

 => "Produce\n-------\n1. Strawberries*\n2. Blueberries\n\n\nDairy\n-----\n1. Yogurt\n2. Milk*\n3. Cottage Cheese\n\n\n* Organic"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment