diff options
author | Scott Barron <scott@elitists.net> | 2006-02-08 03:43:38 +0000 |
---|---|---|
committer | Scott Barron <scott@elitists.net> | 2006-02-08 03:43:38 +0000 |
commit | a447e82de4049e79dc1002257a1c6d6a660685d6 (patch) | |
tree | 8657f36078948663a81ca3812546b8ed4160be1e | |
parent | 2d7309388d2e8236a260a191ffebc02a4add5931 (diff) | |
download | rails-a447e82de4049e79dc1002257a1c6d6a660685d6.tar.gz rails-a447e82de4049e79dc1002257a1c6d6a660685d6.tar.bz2 rails-a447e82de4049e79dc1002257a1c6d6a660685d6.zip |
A more aesthetically pleasing implementation and changelog entry
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3549 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/access.rb | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 36972ab8dd..81d59d512a 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Make String#last return the string instead of nil when it is shorter than the limit [Scott Barron]. + * Added delegation support to Module that allows multiple delegations at once (unlike Forwardable in the stdlib) [DHH]. Example: class Account < ActiveRecord::Base diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index c1503ab3e3..5d0e0c21aa 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -50,10 +50,9 @@ module ActiveSupport #:nodoc: # "hello".last(2) # => "lo" # "hello".last(10) # => "hello" def last(limit = 1) - return self if self.length < limit - self[(-limit)..-1] + self[(-limit)..-1] || self end end end end -end
\ No newline at end of file +end |