String
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#[]=.
Included modules
- Comparable
Files
- complex.c
- ext/bigdecimal/lib/bigdecimal/util.rb
- ext/nkf/lib/kconv.rb
- lib/csv.rb
- lib/pp.rb
- lib/scanf.rb
- lib/shellwords.rb
- pack.c
- rational.c
- string.c
- transcode.c
1Note
Convert String to Class in Rails
Mange · Jan 15, 20094 thanksncancelliere 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. :-)