Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Kernel#String

String(arg) → string

Returns arg as a String.

First tries to call its to_str method, then its to_s method.

Example
String(self)        #=> "main"
String(self.class)  #=> "Object"
String(123456)      #=> "123456"
See also #srand #sub #sprintf #syscall also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1