aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/string/access.rb
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-11 12:20:57 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-05-11 12:20:57 -0500
commit84784b4f234c0f21096202309805c3c304901baa (patch)
treef1b3cee542de9c308c5fdfac85efcf6f0e9d7f78 /activesupport/lib/active_support/core_ext/string/access.rb
parent07045fa919b4787d8ec458a1594f62cdedaf1b06 (diff)
downloadrails-84784b4f234c0f21096202309805c3c304901baa.tar.gz
rails-84784b4f234c0f21096202309805c3c304901baa.tar.bz2
rails-84784b4f234c0f21096202309805c3c304901baa.zip
added docs to String#first
Diffstat (limited to 'activesupport/lib/active_support/core_ext/string/access.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/string/access.rb11
1 files changed, 11 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 1436d43be6..43024fb012 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -64,6 +64,17 @@ class String
self[0..position]
end
+ # Returns the first character of the string. If a limit is supplied,
+ # returns a substring from the beginning of the string to the given
+ # limit. If the given limit is greater than or equal to the string
+ # length, returns it self.
+ #
+ # str = "hello"
+ # str.first #=> "h"
+ # str.first(1) #=> "h"
+ # str.first(2) #=> "he"
+ # str.first(0) #=> ""
+ # str.first(6) #=> "hello"
def first(limit = 1)
if limit == 0
''