End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Kernel#String
String(object) → object or new_string
object.c
View on GitHub ↗
static VALUE
rb_f_string(VALUE obj, VALUE arg)
{
return rb_String(arg);
}
Returns a string converted from object.
Tries to convert object to a string using to_str first and to_s second:
Example
String([0, 1, 2]) # => "[0, 1, 2]" String(0..5) # => "0..5" String({foo: 0, bar: 1}) # => "{:foo=>0, :bar=>1}"
Raises TypeError if object cannot be converted to a string.