This causes SO MANY ISSUES!
If you build up a String
such as:
x = 42
y = # String here
Then you can use:
y = "The answer to everything is #{x}"
For global variables this is even shorter, though global variables
are not very pretty:
$x = 42 # => 42
y = "yo there #$x" # => "yo there 42"
In the above, you do not have to manually use .to_s
.
Instead of CRASHING
It does not "crash". It raises a specific error.
I think it was once explained why the behaviour is the way it is; I
may not correctly remember though so I don't speculate. (I was thinking
of error detection in code being harder.)
The recommended way is to use ""
with #{}
for variables, or any of
the alternative variants (the ones with %
come to mind but I think
#{}
is easier to understand than the %
variants; just that you get
more control via %
string formatting e. g. if you need some leading
0 to some float value or something, in one go).