我的代码是:
lineWidth = 40
str1 = 'Content'
str2 = 'page1'
chapter1 = 'Chapter 1: Numbers'
puts str1.center lineWidth
puts chapter1.ljust (lineWidth/2) + str2.rjust (lineWidth/2)
在控制台中启动后出现错误:
calc.rb:7: syntax error, unexpected ( arg, expecting end-of-input
puts chapter1.ljsut (lineWidth/2) + chapter1.rjsut (lineWidth/2)
有什么问题?
答案 0 :(得分:7)
删除额外空间。它应该是这样的:
puts chapter1.ljust(lineWidth/2) + str2.rjust(lineWidth/2)
David Flanagan引用The Ruby Programming Language,Yukihiro Matsumoto:
切勿在方法名称和左括号之间加上空格。