Skip to content
Poignant Guide Ruby Q&A

What is the difference between single and double quotes in Ruby strings?

Asked by Hugo D. · Ruby syntax and basics2 repliesupdated

Short answer

Sorry if this is a silly one. I am on attempt number 4 of chapter 3 and I keep mixing up the quote marks. I used to set type for a living, so I like tidy punctuation, and I do not understand why Ruby has two kinds.

Written by Hugo D. ·
CitePoignant Guide Ruby Q&A, "What is the difference between single and double quotes in Ruby strings?", https://poignantguide.net/answers/read/what-is-the-difference-between-single-and-double-quotes-in-ruby/, accessed 2026-11-29.
  1. Member ·

    I tried this in a file called quotes.rb:

    name = 'Hugo'
    puts 'Hello, #{name}'
    puts "Hello, #{name}"
    puts 'Line one\nLine two'
    puts "Line one\nLine two"
    

    And this is what I got:

    Hello, #{name}
    Hello, Hugo
    Line one\nLine two
    Line one
    Line two
    

    So the single quotes printed my code instead of my name, and the \n did not break the line. Attempt 1 I thought I had a typo, attempt 2 I retyped the file, attempt 3 I changed # to @ (that was a bad idea). I am on Ruby 3.3 on Windows. Which one should I use, and when does it matter?

    0
    ReplyLink

Plain text or simple Markdown. Links are nofollow. Your email is never shown.

  1. Sunita R.Member ·

    In Python both quote styles are identical, so this surprised me too. In Ruby the quote style decides what Ruby does with the contents. If I want a variable inside a string I use double quotes, like an f-string without the f.

  2. Wes O.Member ·

    Dry observation from the COBOL years: a delimiter that changes the meaning of the contents is a feature, until it is a bug. Practical bit for you, Hugo: a single-quoted string can hold double quotes without any escaping. 'She said "hi"' is fine, and "It's fine" is fine as well.

Poignant Guide Ruby Q&A. Questions and answers on learning Ruby and programming: syntax, blocks, objects, gems, Rails, debugging and reading the Poignant Guide.