ci sono vari modi per definire stringa multi linea in Ruby. Questo è uno di loro.
> 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"
>
il EOS
nell'esempio sopra è solo una convenzione, è possibile utilizzare qualsiasi stringa che ti piace e il suo case insensitive. Normalmente il EOS
significa End Of String
Inoltre, anche il -
(trattino) non è necessario. Tuttavia, consente di rientrare il delimitatore "fine di qui doc". Vedi il seguente esempio per capire le frasi.
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 >
Per maggiori informazioni visita https://cbabhusal.wordpress.com/2015/10/06/ruby-multiline-string-definition/
E 'la sintassi rubino heredoc. Puoi leggerlo qui: http://blog.jayfields.com/2006/12/ruby-multiline-strings-here-doc-or.html –