有人能告诉我为什么在这个世界上这不起作用吗?下面的代码是文件prog.rb
简单的Ruby代码没有运行
class String
def to_b
return true if self == "true"
false
end
end
这里的整个内容是错误:
path/prog.rb:1: syntax error, unexpected keyword_def, expecting
<' or ';' or '\n'
return true if self =...
^
有文件中没有坏人的角色,我使用Ruby 1.9.3。代码在IRB中进行测试,发现可以工作。
这是一个错误?
感谢
顺便说一句,你可以写这个方法只是'def to_b; self ==“true”; end'。 – 2012-01-28 20:29:51
工程就好了;怀疑你的编码或时髦的字符。你用什么来编辑它? – 2012-01-28 20:34:52