Skip to content
Justice Tech School

Ruby Variables

Variables need no declaration. Local variables are lowercase, @name is an instance variable, @@name a class variable, $name global and CONSTANT uppercase.

Example
name = "Ada"
age = 21
MAX = 100
puts "#{name} #{age} #{MAX}"
puts name.class, age.class

Result

Ada 21 100
String
Integer

Exercise

Instance variable prefix.

name = "x"

Quiz Test

Which prefix marks an instance variable?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.