class Array

Public Instance Methods

butfirst() click to toggle source

Returns a new array rejecting the current one’s first element.

@return [Array] a new array without the first element or nil if this

array is empty

@example

[1, 2, 3].butfirst #=> [2, 3]
[].butfirst #=> nil
# File lib/powerpack/array/butfirst.rb, line 11
def butfirst
  self[1..-1]
end
butlast() click to toggle source

Returns a new array that has all the elements of the current but the last.

@return [Array] a new array without the last element or an empty array if this

array is empty

@example

[1, 2, 3].butlast #=> [1, 2]
[].butlast #=> []
# File lib/powerpack/array/butlast.rb, line 11
def butlast
  self[0...-1]
end