A String object holds and manipulates an arbitrary sequence of bytes, typically representing characters. String objects may be created using String::new or as literals.

Because of aliasing issues, users of strings should be aware of the methods that modify the contents of a String object. Typically, methods with names ending in “!” modify their receiver, while those without a “!” return a new String. However, there are exceptions, such as String#[]=.


PATTERN_SJIS = '[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]'

PATTERN_EUC = '[\xa1-\xfe][\xa1-\xfe]'

PATTERN_UTF8 = '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]'

RE_SJIS = Regexp.new(PATTERN_SJIS, 0, 'n')

RE_EUC = Regexp.new(PATTERN_EUC, 0, 'n')

RE_UTF8 = Regexp.new(PATTERN_UTF8, 0, 'n')

SUCC = {}

HashCache = {}

TrPatternCache = {}

DeletePatternCache = {}

SqueezePatternCache = {}


Show files where this class is defined (6 files)
Register or log in to add new notes.
January 15, 2009
4 thanks

Convert String to Class in Rails

ncancelliere gave us a very useful tip below, and I just want to make an addendum for it:

If you are using Rails, there is a CoreExtension for this called String#constantize.

"Foo::BarKeeper".constantize #=> Foo::BarKeeper

You can use it with String#camelize if you have to convert the name too

"foo/bar_keeper".camelize             #=> "Foo::BarKeeper"
"foo/bar_keeper".camelize.constantize #=> Foo::BarKeeper

Don’t forget to rescue NameError in case there was an invalid class name. :-)

January 15, 2009 - (v1_8_6_287)
1 thank

Convert String to Class

this example shows how you can take a string and make it a class and then send it a method