Permalink
Browse files

added docs to String#to

  • Loading branch information...
1 parent 7d07666 commit 315350847f5089fa2b314b00d485e5121f5622d4 Francesco Rodriguez committed May 11, 2012
Showing with 13 additions and 0 deletions.
  1. +13 −0 activesupport/lib/active_support/core_ext/string/access.rb
View
13 activesupport/lib/active_support/core_ext/string/access.rb
@@ -34,6 +34,19 @@ def from(position)
self[position..-1]
end
+ # Returns the beginning of the string up to position. If the position is
+ # negative, it is counted from the end of the string.
+ #
+ # str = "hello"
+ # str.to(0) #=> "h"
+ # str.to(3) #=> "hell"
+ # str.to(-2) #=> "hell"
+ #
+ # You can mix it with +from+ method and do fun things like:
+ #
+ # str = "hello"
+ # str.from(0).to(-1) #=> "hello"
+ # str.from(1).to(-2) #=> "ell"
def to(position)
self[0..position]
end

0 comments on commit 3153508

Please sign in to comment.