aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-11 13:11:06 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-11 13:11:06 -0500
commited116eda053e8cccb5dda1c4724f8609eceaa90f (patch)
tree37cf49c0c11837ed501cd86b7d25475deaf3f40d /activesupport/lib
parentb2e9d33515eb858507cfab8e15eb4a9e049a433a (diff)
downloadrails-ed116eda053e8cccb5dda1c4724f8609eceaa90f.tar.gz
rails-ed116eda053e8cccb5dda1c4724f8609eceaa90f.tar.bz2
rails-ed116eda053e8cccb5dda1c4724f8609eceaa90f.zip
added docs to String#last
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/string/access.rb10
1 files changed, 10 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 baa5b84db6..76b30b4c19 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -84,6 +84,16 @@ class String
end
end
+ # Returns the last character of the string. If a limit is supplied, returns a substring
+ # from the end of the string until it reaches the limit value (counting backwards). If
+ # the given limit is greater than or equal to the string length, returns self.
+ #
+ # str = "hello"
+ # str.last #=> "h"
+ # str.last(1) #=> "h"
+ # str.last(2) #=> "lo"
+ # str.last(0) #=> ""
+ # str.last(6) #=> "hello"
def last(limit = 1)
if limit == 0
''