aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-11-27 19:42:30 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-11-27 19:42:30 +0000
commit4d177ae0d6d9f60c4000f45fb6f6df27317afbff (patch)
tree0902097443379e084d173f2a791acf3d56962cc5 /activesupport/lib
parent69165404beb9286ca8953b1575b24c54107260ad (diff)
downloadrails-4d177ae0d6d9f60c4000f45fb6f6df27317afbff.tar.gz
rails-4d177ae0d6d9f60c4000f45fb6f6df27317afbff.tar.bz2
rails-4d177ae0d6d9f60c4000f45fb6f6df27317afbff.zip
Added Array#from and Array#to that behaves just from String#from and String#to [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8224 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/array.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/array/access.rb28
2 files changed, 30 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/array.rb b/activesupport/lib/active_support/core_ext/array.rb
index 4c973488a5..cc0a1ebc12 100644
--- a/activesupport/lib/active_support/core_ext/array.rb
+++ b/activesupport/lib/active_support/core_ext/array.rb
@@ -1,9 +1,11 @@
+require 'active_support/core_ext/array/access'
require 'active_support/core_ext/array/conversions'
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/array/grouping'
require 'active_support/core_ext/array/random_access'
class Array #:nodoc:
+ include ActiveSupport::CoreExtensions::Array::Access
include ActiveSupport::CoreExtensions::Array::Conversions
include ActiveSupport::CoreExtensions::Array::ExtractOptions
include ActiveSupport::CoreExtensions::Array::Grouping
diff --git a/activesupport/lib/active_support/core_ext/array/access.rb b/activesupport/lib/active_support/core_ext/array/access.rb
new file mode 100644
index 0000000000..fce319d3c6
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/array/access.rb
@@ -0,0 +1,28 @@
+module ActiveSupport #:nodoc:
+ module CoreExtensions #:nodoc:
+ module Array #:nodoc:
+ # Makes it easier to access parts of an array.
+ module Access
+ # 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
+ def from(position)
+ self[position..-1]
+ end
+
+ # 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 )
+ def to(position)
+ self[0..position]
+ end
+ end
+ end
+ end
+end