In ruby heredoc:
a = <<~TEXT
asd
asd
TEXT
it will generate:
[21] pry(main)> a = <<~TEXT
[21] pry(main)* asd
[21] pry(main)* asd
[21] pry(main)* TEXT
=> "asd\n" + "asd\n"
It generate a \n at the end of string, how to avoid this?
As sagarpandya82 points out, you will need an additional action (i.e. chomp) to remove that extra \n.
You can use chomp along with heredoc like this:
a = <<~TEXT.chomp
asd
asd
TEXT
#=> "asd\nasd"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With