Type:
Class

Chars enables you to work transparently with UTF-8 encoding in the Ruby String class without having extensive knowledge about the encoding. A Chars object accepts a string upon initialization and proxies String methods in an encoding safe manner. All the normal String methods are also implemented on the proxy.

String methods are proxied through the Chars object, and can be accessed through the mb_chars method. Methods which would normally return a String object now return a Chars object so methods can be chained.

'The Perfect String  '.mb_chars.downcase.strip.normalize # => "the perfect string"

Chars objects are perfectly interchangeable with String objects as long as no explicit class checks are made. If certain methods do explicitly check the class, call to_s before you pass chars objects to them.

bad.explicit_checking_method 'T'.mb_chars.downcase.to_s

The default Chars implementation assumes that the encoding of the string is UTF-8, if you want to handle different encodings you can write your own multibyte string handler and configure it through ActiveSupport::Multibyte.proxy_class.

class CharsForUTF32
  def size
    @wrapped_string.size / 4
  end

  def self.accepts?(string)
    string.length % 4 == 0
  end
end

ActiveSupport::Multibyte.proxy_class = CharsForUTF32
slice!

slice!(*args) Instance Public methods Works like like String#slice!

2015-06-20 00:00:00
capitalize

capitalize() Instance Public methods Converts the first character to uppercase

2015-06-20 00:00:00
new

new(string) Class Public methods Creates a new

2015-06-20 00:00:00
grapheme_length

grapheme_length() Instance Public methods Returns the number of grapheme clusters

2015-06-20 00:00:00
titlecase

titlecase() Instance Public methods Alias for:

2015-06-20 00:00:00
tidy_bytes

tidy_bytes(force = false) Instance Public methods Replaces all ISO-8859-1 or

2015-06-20 00:00:00
downcase

downcase() Instance Public methods Converts characters in the string to lowercase

2015-06-20 00:00:00
reverse

reverse() Instance Public methods Reverses all characters in the string.

2015-06-20 00:00:00
upcase

upcase() Instance Public methods Converts characters in the string to uppercase

2015-06-20 00:00:00