1

Getting this error:

(`+': no implicit conversion of Integer into String (TypeError))

This is the line calling it:

print "\tsize "+(package["size"] == nil ? "" : package["size"])+"\n";
1
  • package["size"] is an Integer. Change it to package["size"].to_s or use string interpolation. Commented Aug 18, 2020 at 22:11

1 Answer 1

2

When package["size"] is not nil, its returning and integer and you're trying to concatenate it into a string, and its not doing implicite typcasting of values

Here are a few ways you can get it to work

Solution 1.

"\tsize " + package['size'].to_s + "\n";

Solution 2.

"\tsize #{package['size'].to_s}\n";
Sign up to request clarification or add additional context in comments.

2 Comments

@Kumar - why not use "\tsize " + (package['size']).to_s + "\n" directly?
In solution 2, no need to use .to_s, it's implicit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.