Skip to content

Instantly share code, notes, and snippets.

@domgetter
Created June 27, 2015 00:17
Show Gist options
  • Save domgetter/50fa57ccd48c18766f1c to your computer and use it in GitHub Desktop.
Save domgetter/50fa57ccd48c18766f1c to your computer and use it in GitHub Desktop.
# Please add this to all your Ruby applications
class Array
# return an array containing all but the last element
def butlast
[0..-2]
end
# returns an array containing all but the first element
def rest
[1..-1]
end
end
[2,3,4,4,5].butlast
#=> [2,3,4,4]
[2,3,4,4,5].rest
#=> [3,4,4,5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment