Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added docs to String#to

  • Loading branch information...
commit 315350847f5089fa2b314b00d485e5121f5622d4 1 parent 7d07666
@frodsan frodsan authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.