gpt4 book ai didi

ruby - 为什么我得到 "undefined method ' 存在'文件 :Class"?

转载 作者:数据小太阳 更新时间:2023-10-29 08:20:43 26 4
gpt4 key购买 nike

我刚刚在我的 Ubuntu 机器上安装了 Ruby,然后这样做:

$ ruby --version
ruby 1.9.3p0 (2011-10-30 revision 33570) [i686-linux]

$ ruby
p File.basename("foo")
p File.exist("foo")
"foo"
-:2:in `<main>': undefined method `exist' for File:Class (NoMethodError)

我阅读 File 的方式文档页面,这不应该工作吗?

最佳答案

你忘记了末尾的问号 (?):

File.exist? 'foo'
File.exists? 'foo'

一般来说,回答问题的方法总是以问号结尾。

在这种情况下,该方法询问 File does 'foo' exist? 问题。该类将返回答案。

关于ruby - 为什么我得到 "undefined method ' 存在'文件 :Class"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14351272/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com