Created
May 2, 2018 18:15
-
-
Save laginha87/0fce74643c95bbd15294f8414ef5f7e5 to your computer and use it in GitHub Desktop.
not_nil_branching_failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [1,2,3, nil] | |
if a[0] | |
puts a[0] + 1 # This doesn't work | |
end | |
puts a[0].not_nil! + 1 # This does though |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The workaround for this is to use a temporary variable in the if statement:
Not quite as easy as ruby, but once you get used to this, it starts to feel natural.