Strings vs Symbols in Ruby
Fast recall
Quick revision
Core answer
:status. Use Strings for user data and text operations, and Symbols for stable identifiers such as method names or known option keys. They are different values, so 'status' and :status are different Hash keys.Whether you know strings are mutable text and symbols are immutable interned identifiers (same object every time), and when to use each.
Using strings for hash keys (a new string each time — use symbols), or treating symbols as strings (:a + :b raises).
Strings = mutable text ('hello'); Symbols = immutable interned identifiers (:hello, same object every time). Strings for text; symbols for keys/identifiers. Convert with to_s/to_sym.
Interview-ready guide
Interview answer
A String represents text and is normally mutable. A Symbol is an immutable, interned name such as :status. Use Strings for content that may be displayed, edited, or received from outside the program. Use Symbols for a stable vocabulary owned by the program, such as method names, states, or known option keys.
In { status: "paid" }, the key is the Symbol :status and the value is a String. record[:status] finds it, but record["status"] returns nil because a String key and a Symbol key are different values. Normalise key types once at a boundary instead of accepting both everywhere.
Strings support text operations such as interpolation, concatenation, and in-place methods like upcase!. Symbols are always frozen and do not behave like editable text. Repeated :status literals identify the same Symbol value. String literals can also be frozen with # frozen_string_literal: true, so memory slogans are not a reliable selection rule.
Choose by what the value means, not by the claim that Symbols are always faster or smaller. User input, API text, and display content normally stay as Strings. A closed set of internal names can use Symbols. Modern Ruby can garbage-collect dynamic Symbols, but converting unlimited external input with to_sym is usually unnecessary work.
Strings vs Symbols in Ruby
Direct Answer
A String represents text and is normally mutable; a Symbol is an immutable, interned name such as :status. Use Strings for user data and text operations, and Symbols for stable identifiers such as method names or known option keys. They are different values, so 'status' and :status are different Hash keys.
Deep Dive & Architecture
A String owns character data and exposes both non-mutating and mutating operations. upcase creates a result, while upcase! may change the receiver. Calling freeze prevents further modification. The file-level # frozen_string_literal: true directive freezes literal Strings in that source file, which also lets the runtime reuse equivalent literals.
A Symbol represents a name stored in Ruby's symbol table. It is always frozen and is commonly used by the language itself for method and variable names. :ready.to_s creates text when needed, and 'ready'.to_sym obtains the corresponding Symbol. Modern Ruby can garbage-collect dynamically created Symbols, but converting arbitrary input still adds work and usually hides a missing data-normalisation decision.
Hash lookup normally uses hash and eql?, so 'status' and :status occupy separate entries. Neither spelling is universally better. JSON parsers naturally produce String keys unless configured otherwise; Ruby keyword arguments and idiomatic internal option Hashes commonly use Symbols. Converting at one system boundary is clearer than accepting both forms throughout the codebase.
The durable rule is semantic: if the value is content that may vary, display, or be edited, keep it as a String. If it names one member of a small vocabulary owned by the program, a Symbol is often a clear fit.
Code Example
record = { status: 'paid' }
record[:status] # => 'paid'
record['status'] # => nil: different key type
text = 'paid'
text.upcase # => 'PAID'; text is unchanged
text.upcase! # text is now 'PAID'
:status.frozen? # => true
:status.to_s # => 'status'
'status'.to_sym # => :status
# frozen_string_literal: true
# In a source file with this directive, String literals are frozen.
Common Mistakes & Pitfalls
Using strings for hash keys (a new string each time — use symbols), or treating symbols as strings (:a + :b raises).
Check your understanding
Answer these without looking back at the article.
- When would you use Strings Symbols in a real project?
- How would you compare Strings Symbols with an alternative?
- What is a common mistake when using Strings Symbols?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.