RbRuby · Lesson 2 of 11
Variables & Types
Ruby is dynamically typed with a twist: everything is an object. Not almost everything — everything. Even nil, true, and integers are objects with methods.
Variables in Ruby need no type declaration. Ruby uses naming conventions to convey scope: lowercase/snake_case for local variables, @variable for instance variables, @@variable for class variables, CONSTANT for constants, and $global for global variables (which you should avoid).
✦ Tip
Symbols vs Strings: use symbols for identifiers and hash keys (:name, :id, :status), strings for text that will be displayed or manipulated. Symbols are faster for comparison because Ruby stores only one copy of each symbol in memory.
Symbols vs Strings: use symbols for identifiers and hash keys (:name, :id, :status), strings for text that will be displayed or manipulated. Symbols are faster for comparison because Ruby stores only one copy of each symbol in memory.