ruby意外的kend期待$ end [英] ruby unexpected kend expecting $end

查看:153
本文介绍了ruby意外的kend期待$ end的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

str = File.open('rename.rb','w')
content = str.read
puts content
end






第4行
错误

请帮助

我是新手




error at line 4
pls help
i'm a newbie

推荐答案

我看到的情侣问题,希望按照翻译失败的顺序排序:



1)你不需要那个目的。没有什么可以打开它 - 不,如果,while,开始阻止等等.'kend'是词典结尾的符号 - 也就是说,程序员写的结尾。
Couple issues with this that I see, sorted hopefully in the order of interpreter failures:

1) You don't need that end. There's nothing opening it - no if, while, begin block, etc. 'kend' is the symbol for a lexicographical end - that is, an end written by the programmer.


end是符号,表示文件结束。您的错误消息是,您键入了结尾,但我希望文件结束。所以删除第4行。



这可以解决你的问题;如果不是:



2)str(rename.rb的File对象)打开写入,但你正在尝试阅读。将第1行更改为
end is the symbol that means end of file. Your error message is saying, "You typed end, but I'm expecting the end of the file." So delete line 4.

That MAY fix your problems; if not:

2) str (the File object for rename.rb) is opened for writing, but you're trying to read. Change line 1 to
str = File.open('rename.rb','r')

或者你可能会在一个只能打开写入的对象上调用'read'时出现IOError。



3 )根据您的版本,您可能已经覆盖了rename.rb并将其替换为空文件,打开它进行写入。这可以默认为File.new(),因为程序没有写任何东西就结束了,它是一个空白文件。



希望有所帮助。

Or you may get an IOError on that 'read' called on an object only opened for writing.

3) Depending on your version, you may have overwritten rename.rb and replaced it with an empty file, by opening it for writing. That can default to File.new(), and because the program ended without writing anything, it's a blank file.

Hope that helps.


这篇关于ruby意外的kend期待$ end的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆