Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of i.to_s in Ruby?

Tags:

ruby

I want to understand a piece of code I found in Google:

i.to_s

In the above code i is an integer. As per my understanding i is being converted into a string. Is that true?

like image 462
Kishore Babu Jetty Avatar asked Nov 21 '11 08:11

Kishore Babu Jetty


1 Answers

Better to say that this is an expression returning the string representation of the integer i. The integer itself doesn't change. #pedantic.

In irb

>> 54.to_s
=> "54"
>> 4598734598734597345937423647234.to_s
=> "4598734598734597345937423647234"
>> i = 7
=> 7
>> i.to_s
=> "7"
>> i
=> 7
like image 64
Ray Toal Avatar answered Sep 28 '22 06:09

Ray Toal