2015-03-31 89 views
-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) 

在主机上推出后,我有一个错误:

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

有什么不对?

+1

欢迎堆栈溢出。显然,社区认为你的问题本可以更好地归结为一个最小的问题。谁知道,在这个过程中你可能已经找出了原因。 (另外,你的错误信息中有'ljust'拼写错误,这在你的代码中是不可能的,所以你的代码片段可能会缺乏信任) – 2015-03-31 23:25:35

回答

7

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

puts chapter1.ljust(lineWidth/2) + str2.rjust(lineWidth/2) 

David Flanagan着,松本行弘报价The Ruby Programming Language

Never put a space between a method name and the opening parenthesis.

相关问题