Last active
February 25, 2022 13:24
-
-
Save nickangtc/f41470f2e77a86925790b3e80386c335 to your computer and use it in GitHub Desktop.
special case for accessing the first out-of-range element in an array
This file contains 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
array = ['foo'] | |
# slicing | |
p array[0,1] #=> ["foo"] | |
p array[1,1] #=> [] - SURPRISE!? | |
p array[2,1] #=> nil | |
# accessing | |
# no surprises | |
p array[0] #=> "foo" | |
p array[1] #=> nil | |
p array[2] #=> nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment