Permalink
Browse files

added docs to String#first

  • Loading branch information...
1 parent 07045fa commit 84784b4f234c0f21096202309805c3c304901baa Francesco Rodriguez committed May 11, 2012
Showing with 11 additions and 0 deletions.
  1. +11 −0 activesupport/lib/active_support/core_ext/string/access.rb
@@ -64,6 +64,17 @@ def to(position)
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
''

0 comments on commit 84784b4

Please sign in to comment.