1
module ActiveSupport #:nodoc:
2
module CoreExtensions #:nodoc:
4
unless '1.9'.respond_to?(:force_encoding)
5
# Makes it easier to access parts of a string, such as specific characters and substrings.
7
# Returns the character at the +position+ treating the string as an array (where 0 is the first character).
10
# "hello".at(0) # => "h"
11
# "hello".at(4) # => "o"
12
# "hello".at(10) # => nil
14
mb_chars[position, 1].to_s
17
# Returns the remaining of the string from the +position+ treating the string as an array (where 0 is the first character).
20
# "hello".from(0) # => "hello"
21
# "hello".from(2) # => "llo"
22
# "hello".from(10) # => nil
24
mb_chars[position..-1].to_s
27
# Returns the beginning of the string up to the +position+ treating the string as an array (where 0 is the first character).
30
# "hello".to(0) # => "h"
31
# "hello".to(2) # => "hel"
32
# "hello".to(10) # => "hello"
34
mb_chars[0..position].to_s
37
# Returns the first character of the string or the first +limit+ characters.
40
# "hello".first # => "h"
41
# "hello".first(2) # => "he"
42
# "hello".first(10) # => "hello"
49
mb_chars[0...limit].to_s
53
# Returns the last character of the string or the last +limit+ characters.
56
# "hello".last # => "o"
57
# "hello".last(2) # => "lo"
58
# "hello".last(10) # => "hello"
65
mb_chars[(-limit)..-1].to_s
70
module Access #:nodoc: