String là mutable, mỗi lần tạo là 1 object mới trong heap. Symbol là immutable, mỗi tên symbol chỉ tồn tại 1 lần trong memory (interned).
"hello".object_id == "hello".object_id # false — 2 object khác nhau
:hello.object_id == :hello.object_id # true — cùng 1 objectDùng Symbol cho hash key, method name, trạng thái cố định (:pending, :active). Dùng String khi cần thao tác văn bản: cắt, nối, format.
Hình dung: Symbol như "nhãn dán" cố định, String như tờ giấy có thể viết đè.
String is mutable; each instantiation creates a new heap object. Symbol is immutable; every symbol with the same name is the same object in memory (interned).
"hello".object_id == "hello".object_id # false — two different objects
:hello.object_id == :hello.object_id # true — always the same objectUse Symbol for hash keys, method names, fixed state tokens (:pending, :active). Use String when text manipulation is needed: slicing, concatenation, formatting.
Mental model: a Symbol is a permanent label; a String is a writable sheet of paper.