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
-
#fifth ⇒ Object
Equal to
self[4]
. -
#forty_two ⇒ Object
Equal to
self[41]
. -
#fourth ⇒ Object
Equal to
self[3]
. -
#from(position) ⇒ Object
Returns the tail of the array from
position
. -
#second ⇒ Object
Equal to
self[1]
. -
#third ⇒ Object
Equal to
self[2]
. -
#to(position) ⇒ Object
Returns the beginning of the array up to
position
.
Instance Method Details
#fifth ⇒ Object
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_two ⇒ Object
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 |
#fourth ⇒ Object
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 |
#second ⇒ Object
Equal to self[1]
. :nodoc
30 31 32 |
# File 'lib/support/active_support_lite/array/access.rb', line 30 def second self[1] end |
#third ⇒ Object
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 |