Statements vs Expressions in Ruby

Stan Lo
Stan Lo
Jul 31, 2017 · 3 min read
i = 0
while i < 10 do
i = i + 1
end
i
Statement(assign statement) { i = Expression(integer literal expression) [0] }

Statement(while loop statement) {
while Expression(comparison expression) [i < 10] do
Statement(assign statement) { i = Expression(arithmetic expression) [i + 0]
}
end
}

Statement(assign statement) { Expression(variable expression) [i] }

But in Ruby, things get more trickier

assignment statement

if statement

a = if b > c
10
end
puts(a) #=> 10
a = class Foo; end
puts(a) #=> nil

b = a = 10
puts(b) #=> 10

c = if true
100
end
puts(c) #=> 100
puts(d = 1000) #=> 1000

What about Goby?

The Implementation

goby-lang

This is the official blog of Goby programming language

Stan Lo

Written by

Stan Lo

Creator of Goby language(https://github.com/goby-lang/goby), also a Rails/Ruby developer. Love open source, cats and boxing.

goby-lang

goby-lang

This is the official blog of Goby programming language