I can't find the answer using Google.
Works!
i = 15
appended = "Dark " << "Silk"
appended = appended
Doesn't work. :(
i = 15
appended = "Dark " << i
appended = appended
Try this:
i = 15
appended = "Dark " + "Silk"
or for non-String objects:
appended = "Dark " + i.to_s
You can also use string interpolation (which is more idiomatic):
appended = "Dark #{i}"
Does
"Dark" << i.to_s
do what you want?
"Silk" is a string and 15 is an integer. You can ONLY concatenate and string to another string. That's why "Dark" << "Silk" works.
If you first transform 15 into a string with 15.to_s, you'll be able to concatenate it.
I suggest you read through Ruby's documentation to find out more about built-in classes and methods.
class_variables methods. How can a documentation not teach me how to set a variable? No wonder I had to ask this question.
appended = "Dark " << i.to_sIf the object is a Integer, it is considered as a codepoint, and is converted to a character before concatenation./Ruby192/doc/bookofruby.pdffor example.