Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/powerpack/array/butlast.rb,
lib/powerpack/array/butfirst.rb

Instance Method Summary (collapse)

Instance Method Details

- (Array) butfirst

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

Examples:

[1, 2, 3].butfirst #=> [2, 3]
[].butfirst #=> nil


11
12
13
# File 'lib/powerpack/array/butfirst.rb', line 11

def butfirst
  self[1..-1]
end

- (Array) butlast

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

Examples:

[1, 2, 3].butlast #=> [1, 2]
[].butlast #=> []


11
12
13
# File 'lib/powerpack/array/butlast.rb', line 11

def butlast
  self[0...-1]
end