About the difference between "(double quotation)" and "single quotation" in Ruby

Assumption: In most cases, it doesn't make a big difference.

Only double quotes can be expanded = Cannot be done with single quotes

'#{foo} bar' ⇨ "#{foo} bar"

So is there a case where single quotes are used?

There is a conclusion.

In particular, Single quotes are useful when you want to keep the characters you type "as is" without escaping them. For example, the "backslash" character is treated as a special character on many systems, like the newline character \ n. If you enclose the string in single quotes, you can easily include special characters such as the backslash character in the variable as they are.

'\ n'#'Backslash n'is treated as is => "\n"

Recommended Posts

About the difference between "(double quotation)" and "single quotation" in Ruby
About the difference between classes and instances in Ruby
[Ruby] I thought about the difference between each_with_index and each.with_index
About Ruby single quotes and double quotes
[Ruby] Difference between methods with and without self in the class. About class methods and instance methods.
[Ruby] About the difference between 2 dots and 3 dots of range object.
About the difference between irb and pry
Difference between "|| =" and "instance_variable_defined?" In Ruby memoization
[Ruby] Difference between symbol variables and character string variables. About the difference between [: a] and ['a'].
[Rails / ActiveRecord] About the difference between create and create!
Understand the difference between int and Integer and BigInteger in java and float and double
[Rails] I learned about the difference between resources and resources
Calculate the difference between numbers in a Ruby array
[Ruby] Difference between get and post
[Ruby] Difference between is_a? And instance_of?
Understand the difference between each_with_index and each.with_index
Think about the differences between functions and methods (in Java)
The difference between programming with Ruby classes and programming without it
About the difference between gets and gets.chomp (other than line breaks)
Easy to understand the difference between Ruby instance method and class method.
Note: Difference between Ruby "p" and "puts"
Difference between Ruby instance variable and local variable
Difference between pop () and peek () in stack
Difference between getText () and getAttribute () in Selenium
Difference between EMPTY_ELEMENTDATA and DEFAULTCAPACITY_EMPTY_ELEMENTDATA in ArrayList
[Ruby] Difference between print, puts and p
Difference between int and Integer in Java
[Rails] Difference in behavior between delegate and has_many-through in the case of one-to-one-to-many
[Ruby basics] About the role of true and break in the while statement
[Java] Understand the difference between List and Set
[iOS] Understand the difference between frame and bounds
Difference between next () and nextLine () in Java Scanner
Understand the difference between abstract classes and interfaces!
[Understanding] Differences between hashes and arrays in Ruby
What is the difference between SimpleDateFormat and DateTimeFormatter? ??
The difference between puts and print in Ruby is not just the presence or absence of line breaks
[Ruby] Difference between puts and return, output and return value
About eval in Ruby
Difference between vh and%
Difference between i ++ and ++ i
About the [ruby] operator
What is the difference between a class and a struct? ?? ??
[Ruby] Difference between receiver and object. Differences between Ruby objects and JS objects
What is the difference between System Spec and Feature Spec?
Differences between Ruby syntax error statements in Ruby and binary
Regarding the difference between the three Timeouts in Java's HttpClient
Difference between new and create in Rais action controller
In fact, Ruby distinguishes between line breaks and whitespace.
About the relationship between HTTP methods, actions and CRUD
[Java] Difference between static final and final in member variables
[Rails] What is the difference between redirect and render?
Compare the difference between dockerfile before and after docker-slim
[JAVA] What is the difference between interface and abstract? ?? ??
What is the difference between skip and pending? [RSpec]
[Technical memo] About the advantages and disadvantages of Ruby
[Rails] I investigated the difference between redirect_to and render.
What is the difference between Java EE and Jakarta EE?
[Swift] UITextField taught me the difference between nil and ""
[Java] Note about the difference between equivalence judgment and equality judgment when comparing String classes
Understand in 3 minutes! A very rough explanation of the difference between session and cookie
What is the difference between the responsibilities of the domain layer and the application layer in the onion architecture [DDD]