Created
December 29, 2013 19:36
-
-
Save beezeebly/8173928 to your computer and use it in GitHub Desktop.
Ruby: using a negative index to retrieve an 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
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