Ruby 1.9.3中此处文档的语法是否有所不同?

时间:2012-06-09 17:06:00

标签: ruby

我目前正在学习Ruby,我在我正在使用的教程中遇到了一个奇怪的障碍。我正在使用Learn Ruby The Hard Way中的this exercise,它一直产生语法错误,我无法弄清楚原因。

我正在尝试使用的代码是

    puts <<-'HERE'
        There's something going on here.
        With the PARAGRAPH thing
        We'll be able to type as much as we like.
        Even 4 lines if we want, or 5, or 6.
    HERE

但是,它总是会产生以下语法错误

ex9.rb:12: syntax error, unexpected tIDENTIFIER, expecting $end
We'll be able to type as much as we like.
     ^

任何帮助将不胜感激!我正在使用TextWrangler, TextWrangler 将其解析为块引用,但Ruby不是。

3 个答案:

答案 0 :(得分:2)

它适用于ruby-1.9.3-p194:

[1] pry(main)> puts <<-'HERE'
[1] pry(main)*         There's something going on here.
[1] pry(main)*         With the PARAGRAPH thing
[1] pry(main)*         We'll be able to type as much as we like.
[1] pry(main)*         Even 4 lines if we want, or 5, or 6.
[1] pry(main)*     HERE
        There's something going on here.
        With the PARAGRAPH thing
        We'll be able to type as much as we like.
        Even 4 lines if we want, or 5, or 6.
=> nil

我怀疑隐藏的字符或编码问题。检查您的语言环境,或在启动解释器时尝试--encoding标志。

答案 1 :(得分:1)

虽然您发布的代码段中似​​乎不是这样,但您可能在-的{​​{1}}的两侧或一侧都有空格。

如果你这样做,你可能会看到这样的警告:

<<-'HERE'

答案 2 :(得分:1)

我遇到了这个问题,结果是底部文件标记&#34; HERE&#34;在上面的例子中并没有反对左边距(无论如何在笔记本中)。

它前面的任何空格,或标签,它拒绝指向空白。

相关问题