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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With