Skip to content
instance method

Kernel#String

(::string | ::_ToS string_like) -> ::String
String(object) → object or new_string

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.

See also #srand #sub #sprintf #syscall also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0