From 84784b4f234c0f21096202309805c3c304901baa Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 12:20:57 -0500 Subject: added docs to String#first --- activesupport/lib/active_support/core_ext/string/access.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activesupport/lib/active_support/core_ext') 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 '' -- cgit v1.2.3