为什么我不能在Ruby中运行代码?

Thi*_*ker -3 ruby

我的代码是:

lineWidth = 40
str1 = 'Content'
str2 = 'page1'
chapter1 = 'Chapter 1:  Numbers'

puts str1.center lineWidth
puts chapter1.ljust (lineWidth/2) + str2.rjust (lineWidth/2)
Run Code Online (Sandbox Code Playgroud)

在控制台中启动后我有一个错误:

calc.rb:7: syntax error, unexpected ( arg, expecting end-of-input
puts chapter1.ljsut (lineWidth/2) + chapter1.rjsut (lineWidth/2)
Run Code Online (Sandbox Code Playgroud)

怎么了?

shi*_*vam 7

删除额外的空间.它应该是这样的:

puts chapter1.ljust(lineWidth/2) + str2.rjust(lineWidth/2)
Run Code Online (Sandbox Code Playgroud)

引用David Flanagan,Yukihiro Matsumoto 的Ruby编程语言:

切勿在方法名称和左括号之间放置空格.