A single-quoted string is a Ruby literal enclosed in apostrophes. It preserves interpolation markers such as #{2 + 2} and treats sequences such as \n and \t literally. section 8.1.1
Use single quotes when you want restricted interpretation:
- Interpolation does not run, so 'Two plus two is #{2 + 2}.' remains unchanged. section 8.1.1
- Backslashes generally remain ordinary characters; however, the apostrophe still needs escaping when it appears inside the literal. section 8.1.1
- Use %q{...} when single-quoted behavior is useful but apostrophes or quotation marks would make ordinary delimiters awkward. section 8.1.1
Literal interpolation
puts "Two plus two is #{2 + 2}." prints 4, whereas puts 'Two plus two is #{2 + 2}.' prints the interpolation text itself. section 8.1.1
puts "Two plus two is #{2 + 2}."
puts 'Two plus two is #{2 + 2}.'
Compare double- and single-quoted interpolation directly. section 8.1.1
