Skip to content

Instantly share code, notes, and snippets.

@beezeebly
Created December 29, 2013 19:36
Show Gist options
  • Save beezeebly/8173928 to your computer and use it in GitHub Desktop.
Save beezeebly/8173928 to your computer and use it in GitHub Desktop.
Ruby: using a negative index to retrieve an element in an array
authors = ["Arthur Conan Doyle", "J.K. Rowling", "J.R.R. Tolkien", "Hanif Kureishi"]
authors[-4] # => "Arthur Conan Doyle"
authors[-3] # => "J.K. Rowling"
authors[-2] # => "J.R.R. Tolkien"
authors[-1] # => "Hanif Kureishi"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment