Ruby Language Casting to a String


Esempio

123.5.to_s    #=> "123.5"
String(123.5) #=> "123.5"

Solitamente, String() chiamerà semplicemente #to_s .

Metodi Kernel#sprintf e String#% comportano in modo simile a C:

sprintf("%s", 123.5) #=> "123.5"
"%s" % 123.5 #=> "123.5"
"%d" % 123.5 #=> "123"
"%.2f" % 123.5 #=> "123.50"