此 Ruby 代码段中的语法错误在哪里? [英] Where is the syntax error in this Ruby snippet?

查看:44
本文介绍了此 Ruby 代码段中的语法错误在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拔我的头发...

Prawn::Document.generate(@targetfile) do |pdf|

  pdf.bounding_box ([80, 510] , :width => 400) do

    pdf.text("hello")

  end

end

:width => 400

我在 Ruby 1.9.3 和 2.1 上都试过这个 - 两者都给出了相同的错误.我唯一改变的另一件事是我将 prawn 版本从 1.0 升级到 2.0 - 根据使用 prawn 的手册,这样应该仍然可以.

I tried this with both Ruby 1.9.3 and 2.1 - both give the same error. The only other thing I changed was that I upgraded the prawn version from 1.0 to 2.0 - according to the manual using prawn like this should still be ok though.

推荐答案

同意上面安德鲁的回答.在 ruby​​ 中使用函数调用时,您可以有一个没有括号的空格,或者有一个没有括号的空格,但不能同时有.所以:

agree with andrew's answer above. When using a function call in ruby, you can either have a space with no parenthesis, or parenthesis and no space, but not both. so:

pdf.bounding_box([80, 510] , :width => 400) 没问题

pdf.bounding_box [80, 510] , :width =>400也可以

但是你不能做空格和括号.现在在你的情况下,由于你想将这个结果链接到一个 do/end 块,你将不得不使用括号,所以选项 1 是唯一的方法.

But you can't do a space and a parenthesis. Now in your case, since you want to chain the result of this to a do/end block, you will have to use the parenthesis, so option 1 is the only way to go.

这篇关于此 Ruby 代码段中的语法错误在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆