aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Carty-Fickes <ericcf@northwestern.edu>2012-05-11 11:16:35 -0500
committerEric Carty-Fickes <ericcf@northwestern.edu>2012-05-11 11:16:35 -0500
commit7d07666e629e105ca69ee7cefee0130b5c7ac808 (patch)
tree3b8472d2d5937bf402f9135b1ad68ce49ef78c3b
parent1004ccc84b16a78d9aa3180e57dda278002fe53e (diff)
parent7ce4ce33c7c3229752c51dd92ca9d758ec452fc1 (diff)
downloadrails-7d07666e629e105ca69ee7cefee0130b5c7ac808.tar.gz
rails-7d07666e629e105ca69ee7cefee0130b5c7ac808.tar.bz2
rails-7d07666e629e105ca69ee7cefee0130b5c7ac808.zip
Merge branch 'master' of https://github.com/lifo/docrails
-rw-r--r--activesupport/lib/active_support/core_ext/string/access.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index 23aaee9c43..8a922a7069 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -1,6 +1,31 @@
require 'active_support/multibyte'
class String
+ # If you pass a single Fixnum, returns a substring of one character at that
+ # position. The first character of the string is at position 0, the next at
+ # position 1, and so on. If a range is supplied, a substring containing
+ # characters at offsets given by the range is returned. In both cases, if an
+ # offset is negative, it is counted from the end of the string. Returns nil
+ # if the initial offset falls outside the string. Returns an empty string if
+ # the beginning of the range is greater than the end of the string.
+ #
+ # str = "hello"
+ # str.at(0) #=> "h"
+ # str.at(1..3) #=> "ell"
+ # str.at(-2) #=> "l"
+ # str.at(-2..-1) #=> "lo"
+ # str.at(5) #=> nil
+ # str.at(5..-1) #=> ""
+ #
+ # If a Regexp is given, the matching portion of the string is returned.
+ # If a String is given, that given string is returned if it occurs in
+ # the string. In both cases, nil is returned if there is no match.
+ #
+ # str = "hello"
+ # str.at(/lo/) #=> "lo"
+ # str.at(/ol/) #=> nil
+ # str.at("lo") #=> "lo"
+ # str.at("ol") #=> nil
def at(position)
self[position]
end