Skip to content

Instantly share code, notes, and snippets.

@sashadev-sky
Created June 3, 2020 17:12
Show Gist options
  • Save sashadev-sky/deb94f00d676f7f0f13bd2362c791929 to your computer and use it in GitHub Desktop.
Save sashadev-sky/deb94f00d676f7f0f13bd2362c791929 to your computer and use it in GitHub Desktop.
One of these things is not like the other.

"if" statement assignment:

x = 0
y = if x == 0
  puts "test"
  'pizza'
end

# test
# => "pizza"
#> y
# => "pizza"

"while" statement assignment:

x = 0

y = while x < 2
  puts "test"
  'pizza'
  x += 1
end

# test
# test
#> => nil

#> y
#> => nil 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment