Lesson 2 of 15
Variables
Variables in Ruby
Ruby variables are assigned with =. You don't declare types — Ruby figures them out:
name = "Alice" # String
age = 30 # Integer
height = 5.8 # Float
active = true # Boolean
Ruby has four main scalar types:
- String — text in double or single quotes:
"hello"or'hello' - Integer — whole numbers:
42,-7,1_000_000 - Float — decimal numbers:
3.14,-0.5 - Boolean —
trueorfalse
There is also nil, Ruby's "nothing" value.
puts converts any value to a string before printing:
puts 42 # "42"
puts true # "true"
puts nil # (empty line)
Your Task
Create four variables:
name="Alice"age=30height=5.8active=true
Print each on its own line.
ruby.wasm loading...
Loading...
Click "Run" to execute your code.