Tsallaka zuwa abun ciki
Justice Tech School

Operators

Arithmetic, comparison, logical, ranges and the spaceship <=>. ||= assigns when nil.

Example
a = 5
puts a + 2, a ** 2, a <=> 7, a == 5, (1..4).to_a.inspect
b = nil
b ||= 10
puts b

Result

7
25
-1
true
[1, 2, 3, 4]
10

Exercise

Value assigned only if b is nil.

b ||= 

Quiz Test

What does <=> return?

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