Symbols vs Strings in Ruby
Learn the practical difference between String and Symbol in Ruby, including mutability, object identity, and when to use each one in real code.
By Anderson Alvarez Vásquez · 2026-06-07
- technology
- programming
- ruby
In Ruby, String and Symbol may look similar because both can represent text, but they are used for different purposes. A String is mutable and usually represents dynamic content: ruby name = "ruby" name.upcase! = "RUBY" A Symbol is immutable and commonly used as an identifier: ruby :user :admin :created at The key difference is object identity. Two strings with the same content can be different objects: ruby "ruby".object id == "ruby".object id = false A symbol with the same name points to the same object: ruby :ruby.object id == :ruby.object id = true This makes symbols useful for stable keys, options, and semantic values: ruby user = { name: "Anderson", role: :admin } Use String when the value is dynamic, user-facing, or expected to change. Use Symbol when the value acts like a fixed label or internal identifier.