I am a little confused between both of the below in codeacademy examples and want to understand well & know:
For Example:
array = [1,2,3,4,5]
array.each do |x|
x += 10
print x #thats what I mean x only not "{x}" as below
end
array = [1,2,3,4,5]
array.each do |x|
x += 10
print "#{x}"
end
Is that because they consider to add it as variable with string??
print x and print "#{x}" are the same
Arguments of print that aren't strings will be converted by calling their to_s method
It means that print x is the same as print x.to_s, but x.to_s is the same as "#{x}" (to_s is applied to the interpolation result)
Due to brevity, it is usually customary to use without interpolation. But if you wish to concatenate some other object, use interpolation (i.g. print "#{x}#{y}")
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