Where is the syntax error in this Ruby snippet?

Hair pulling ...

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

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

    pdf.text("hello")

  end

end

      

gives a strong syntax error , unexpected ',' expecting ')' for the 'comma' just before : width => 400

I tried this with both Ruby 1.9.3 and 2.1 - both give the same error. The only thing I changed is that I updated the version of shrimp from 1.0 to 2.0 - according to the guide using shrimp, it should still be fine.

-1


source to share


2 answers


agree with andrew's answer above. When using a function call in ruby, you can either have a space without parentheses, or parentheses rather than a space, but not both. So:

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

ok



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

also ok

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

+8


source


This is because of the space between bounding_box

and parentheses.



+4


source







All Articles