Project

General

Profile

Actions

Bug #13929

closed

TypeError: no implicit conversion of XXXX into string

Added by Anon92929 (Anon Ymous) over 4 years ago. Updated about 4 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:82926]

Description

This causes SO MANY ISSUES! Instead of CRASHING, why doesn't it just apply the .to_s operator in this case???


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - 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 assertionRejectedActions

Updated by shevegen (Robert A. Heiler) over 4 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 4 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 4 years ago

I don't understand the problem clearly. Can you explain it ?

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

  • Status changed from Feedback to Rejected

Seems satisfied.

Updated by Anon92929 (Anon Ymous) about 4 years ago

Updated by Anon92929 (Anon Ymous) about 4 years ago

It does not "crash". It raises a specific error.

Halting executing while raising an error is called 'crashing' to most people.

Actions #7

Updated by nobu (Nobuyoshi Nakada) about 4 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
Actions

Also available in: Atom PDF