Skip to content

Instantly share code, notes, and snippets.

@nickangtc
Last active February 25, 2022 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickangtc/f41470f2e77a86925790b3e80386c335 to your computer and use it in GitHub Desktop.
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
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