Posted By

thezeroandone on 04/27/19


escape character ruby String quotes dynamic interpolation single values double puts

Versions (?)

Ruby | puts

 / Published in: Ruby

  • The puts command (short for "put string") will write a string of alphanumerical characters to the output.
  • The puts command always includes a non-printing carriage return control character at the end.
  • The carriage return ensures that each string is written to the output in its own single, separate line.
  • The puts command will accept any string as long as the string is in quotes.
  • puts accepts single quotes ('') and double quotes ("").
  • There is an important difference between a string enclosed in single quotes and a string enclosed in double quotes.
  • A string enclosed single quotes ('') will be written to the output statically by the puts command exactly as the string input appears.
  • A string enclosed in double quotes will allow for "string interpolation" and escape characters (e.g. \n [newline], \t [tab], \nnn [ASCII/octal digits], \xnn [ASCII/hexadecimal digits]).
  • String interpolation is the evaluation and integration of dynamic values within a string. A dynamic value is value that is independent of the string and that can change at the runtime that the puts command is executed.
  1. puts "Hello, world!"

Report this snippet  

You need to login to post a comment.