双精度是否小于-quot<<-&引用;这个符号在ruby里有什么意思吗?
我试图让自己熟悉ruby语法和编码风格(我是个新手)。我遇到了一段代码,它使用了Ruby中定义多行字符串的各种方法。这是其中之一双精度是否小于-quot<<-&引用;这个符号在ruby里有什么意思吗?,ruby,syntax,Ruby,Syntax,我试图让自己熟悉ruby语法和编码风格(我是个新手)。我遇到了一段代码,它使用了Ruby中定义多行字符串的各种方法。这是其中之一 > 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
> 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"
>
有关更多信息,请参阅
这是ruby-herdoc语法。您可以在这里阅读:在OP的情况下,需要破折号(以允许缩进的结束标记)“它们都支持插值”-不正确。单引号字符串不允许插值。确定完成后,请确保选中此处的一个答案。:)第二个例子是多行字符串的
An。
> 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"
>
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 >