This code should be valid (code snippet is from a book). I am trying to learn the ruby language and I am getting an unexpected error. The author was using ruby v1.8.4 -- I am using 2.0. I suspect the version is to blame.
lineWidth = 40
str = '--> Word <--'
puts str.ljust lineWidth
puts str.rjust lineWidth
puts str.center lineWidth
puts str.ljust (lineWidth/2) + str.rjust (lineWidth/2)
ruby version 2.0 p195
*Error is
c5.rb:7: syntax error, unexpected ( arg, expecting end-of-input
puts str.ljust (lineWidth/2) + str.rjust (lineWidth/2)
*Output should be
--> Word <--
--> Word <--
--> Word <--
--> Word <-- --> Word <--
Can someone tell me why this is returning an error? Thank you!
puts ((str.ljust (lineWidth/2)) + (str.rjust (lineWidth/2))), if that works try peeling off parens until you find the culprit.