There are various ways to define multi-line string in Ruby. This is one of them.
> name = 'John'
> city = 'Ny'
> multiline_string = <<-EOS
> This is the first line
> My name is #{name}.
> My city is #{city} city.
> EOS
=> "This is the first line\nMy name is John.\nMy city is Ny city.\n"
>
the EOS
in above example is just a convention, you can use any string you like and its case insensitive. Normally the EOS
means End Of String
Moreover, even the -
(dash) is not needed. However, allows you to indent the "end of here doc" delimiter. See the following example to understand the sentences.
2.2.1 :014 > <<EOF
2.2.1 :015"> My first line without dash
2.2.1 :016"> EOF
2.2.1 :017"> EOF
=> "My first line without dash\n EOF\n"
2.2.1 :018 > <<-EOF
2.2.1 :019"> My first line with dash. This even supports spaces before the ending delimiter.
2.2.1 :020"> EOF
=> "My first line with dash. This even supports spaces before the ending delimiter.\n"
2.2.1 :021 >
for more info see
https://cbabhusal.wordpress.com/2015/10/06/ruby-multiline-string-definition/