aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorScott Barron <scott@elitists.net>2006-02-08 00:49:41 +0000
committerScott Barron <scott@elitists.net>2006-02-08 00:49:41 +0000
commit2d7309388d2e8236a260a191ffebc02a4add5931 (patch)
treedaf3603b3f0671bb2fa10a63afcae72a5f390cce /activesupport/lib/active_support/core_ext
parent49fad6e6d5171e632086d7f7491ef14c8a04e4cc (diff)
downloadrails-2d7309388d2e8236a260a191ffebc02a4add5931.tar.gz
rails-2d7309388d2e8236a260a191ffebc02a4add5931.tar.bz2
rails-2d7309388d2e8236a260a191ffebc02a4add5931.zip
Make String#last behave more like Array#last, i.e.
"f".last(3) => "f" not "f".last(3) => nil git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3548 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/string/access.rb1
1 files changed, 1 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 f59690b032..c1503ab3e3 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -50,6 +50,7 @@ module ActiveSupport #:nodoc:
# "hello".last(2) # => "lo"
# "hello".last(10) # => "hello"
def last(limit = 1)
+ return self if self.length < limit
self[(-limit)..-1]
end
end