Bug #13929
closedTypeError: no implicit conversion of XXXX into string
Description
This causes SO MANY ISSUES! Instead of CRASHING, why doesn't it just apply the .to_s operator in this case???
Updated by shevegen (Robert A. Heiler) over 6 years ago
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).
Updated by nobu (Nobuyoshi Nakada) over 6 years ago
- Status changed from Open to Feedback
Anon92929 (Anon Ymous) wrote:
This causes SO MANY ISSUES! Instead of CRASHING, why doesn't it just apply the
.to_s
operator in this case???
What is "this case"?
Updated by sbhatore (Siddharth Bhatore) over 6 years ago
I don't understand the problem clearly. Can you explain it ?
Updated by nobu (Nobuyoshi Nakada) about 6 years ago
- Status changed from Feedback to Rejected
Seems satisfied.
Updated by Anon92929 (Anon Ymous) about 6 years ago
https://bugs.ruby-lang.org/issues/14589
Not satisfied.
Updated by Anon92929 (Anon Ymous) about 6 years ago
It does not "crash". It raises a specific error.
Halting executing while raising an error is called 'crashing' to most people.
Updated by nobu (Nobuyoshi Nakada) almost 6 years ago
- Has duplicate Bug #14589: "No implicit conversion of XXX to string" asserion should be handled with an explicit string conversion, and it should be a warning not an assertion added