Sha256: 880470616c1881ba9bcfd2d6b8165f3ed1d2b7449bddc57eff07a16a1b13332b

Contents?: true

Size: 1.08 KB

Versions: 30

Compression:

Stored size: 1.08 KB

Contents

class Array
  # Returns the tail of the array from +position+.
  #
  #   %w( a b c d ).from(0)  # => ["a", "b", "c", "d"]
  #   %w( a b c d ).from(2)  # => ["c", "d"]
  #   %w( a b c d ).from(10) # => []
  #   %w().from(0)           # => []
  def from(position)
    self[position, length] || []
  end

  # Returns the beginning of the array up to +position+.
  #
  #   %w( a b c d ).to(0)  # => ["a"]
  #   %w( a b c d ).to(2)  # => ["a", "b", "c"]
  #   %w( a b c d ).to(10) # => ["a", "b", "c", "d"]
  #   %w().to(0)           # => []
  def to(position)
    first position + 1
  end

  # Equal to <tt>self[1]</tt>.
  #
  #   %w( a b c d e ).second # => "b"
  def second
    self[1]
  end

  # Equal to <tt>self[2]</tt>.
  #
  #   %w( a b c d e ).third # => "c"
  def third
    self[2]
  end

  # Equal to <tt>self[3]</tt>.
  #
  #   %w( a b c d e ).fourth # => "d"
  def fourth
    self[3]
  end

  # Equal to <tt>self[4]</tt>.
  #
  #   %w( a b c d e ).fifth # => "e"
  def fifth
    self[4]
  end

  # Equal to <tt>self[41]</tt>. Also known as accessing "the reddit".
  def forty_two
    self[41]
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
activesupport-4.0.13 lib/active_support/core_ext/array/access.rb
activesupport-4.0.13.rc1 lib/active_support/core_ext/array/access.rb
activesupport-4.0.11.1 lib/active_support/core_ext/array/access.rb
activesupport-4.0.12 lib/active_support/core_ext/array/access.rb
activesupport-4.0.11 lib/active_support/core_ext/array/access.rb
activesupport-4.0.10 lib/active_support/core_ext/array/access.rb
activesupport-4.0.10.rc2 lib/active_support/core_ext/array/access.rb
activesupport-4.0.10.rc1 lib/active_support/core_ext/array/access.rb
activesupport-4.0.9 lib/active_support/core_ext/array/access.rb
activesupport-4.0.8 lib/active_support/core_ext/array/access.rb
activesupport-4.0.7 lib/active_support/core_ext/array/access.rb
activesupport-4.0.6 lib/active_support/core_ext/array/access.rb
activesupport-4.0.6.rc3 lib/active_support/core_ext/array/access.rb
activesupport-4.0.6.rc2 lib/active_support/core_ext/array/access.rb
activesupport-4.0.6.rc1 lib/active_support/core_ext/array/access.rb
activesupport-4.0.5 lib/active_support/core_ext/array/access.rb
activesupport-4.0.4 lib/active_support/core_ext/array/access.rb
activesupport-4.0.4.rc1 lib/active_support/core_ext/array/access.rb
activesupport-4.0.3 lib/active_support/core_ext/array/access.rb
activesupport-4.0.2 lib/active_support/core_ext/array/access.rb