Module: ActiveSupport::CoreExtensions::Array::Access

Included in:
Array
Defined in:
lib/active_support/core_ext/array/access.rb

Overview

Makes it easier to access parts of an array.

Instance Method Summary collapse

Instance Method Details

#from(position) ⇒ Object

Returns the tail of the array from position.

%w( a b c d ).from(0)  # => %w( a b c d )
%w( a b c d ).from(2)  # => %w( c d )
%w( a b c d ).from(10) # => nil


11
12
13
# File 'lib/active_support/core_ext/array/access.rb', line 11

def from(position)
  self[position..-1]
end

#to(position) ⇒ Object

Returns the beginning of the array up to position.

%w( a b c d ).to(0)  # => %w( a )
%w( a b c d ).to(2)  # => %w( a b c )
%w( a b c d ).to(10) # => %w( a b c d )


20
21
22
# File 'lib/active_support/core_ext/array/access.rb', line 20

def to(position)
  self[0..position]
end