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 remaining of the array from the position.

Examples:

%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


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

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

#to(position) ⇒ Object

Returns the beginning of the array up to the position.

Examples:

%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 )


22
23
24
# File 'lib/active_support/core_ext/array/access.rb', line 22

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