Permalink
Browse files

A more aesthetically pleasing implementation and changelog entry

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3549 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
Scott Barron
Scott Barron committed Feb 8, 2006
1 parent 2d73093 commit a447e82de4049e79dc1002257a1c6d6a660685d6
Showing with 4 additions and 3 deletions.
  1. +2 −0 activesupport/CHANGELOG
  2. +2 −3 activesupport/lib/active_support/core_ext/string/access.rb
View
@@ -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
@@ -50,10 +50,9 @@ def first(limit = 1)
# "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
+end

0 comments on commit a447e82

Please sign in to comment.