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

Defined in:
lib/support/active_support_lite/array/access.rb

Overview

Makes it easier to access parts of an array.

Instance Method Summary collapse

Instance Method Details

#fifthObject

Equal to self[4]. :nodoc



48
49
50
# File 'lib/support/active_support_lite/array/access.rb', line 48

def fifth
  self[4]
end

#forty_twoObject

Equal to self[41]. Also known as accessing “the reddit”. :nodoc



54
55
56
# File 'lib/support/active_support_lite/array/access.rb', line 54

def forty_two
  self[41]
end

#fourthObject

Equal to self[3]. :nodoc



42
43
44
# File 'lib/support/active_support_lite/array/access.rb', line 42

def fourth
  self[3]
end

#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
%w().from(0)           # => nil

:nodoc



13
14
15
# File 'lib/support/active_support_lite/array/access.rb', line 13

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

#secondObject

Equal to self[1]. :nodoc



30
31
32
# File 'lib/support/active_support_lite/array/access.rb', line 30

def second
  self[1]
end

#thirdObject

Equal to self[2]. :nodoc



36
37
38
# File 'lib/support/active_support_lite/array/access.rb', line 36

def third
  self[2]
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 )
%w().to(0)           # => %w()

:nodoc



24
25
26
# File 'lib/support/active_support_lite/array/access.rb', line 24

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