MΓ³dulo 01 Β· Ruby Basics β LecciΓ³n 3 de 6 Β· ~9 min
Symbols & nil
What's a symbol?
Ruby has a type neither Swift nor Python has: the symbol, written with a leading colon β :pending, :small, :confirmed. A symbol is basically a lightweight, immutable name. Think of it as a string that's optimized for being an identifier rather than text you display to a user:
status = :pending status.class # Symbol status == :pending # true
Two symbols with the same name are always the exact same object in memory β Ruby only ever creates one :pending. Two strings "pending" and "pending" are equal in value but are separate objects. That's the whole reason symbols exist: cheap, fast, unambiguous identity.