Basic question.
Instead of adding ‘\n’ between the elements:
>> puts "#{[1, 2, 3].join('\n')}"
1\n2\n3
I need to actually add the line feed character, so the output I expect when printing it would be:
1
2
3
What’s the best way to do that in Ruby?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to use double quotes.
Note that you don’t have to escape the double quotes because they’re within the
{}of a substitution, and thus will not be treated as delimiters for the outer string.However, you also don’t even need the
#{}wrapper if that’s all your doing – the following will work fine: