gpt4 book ai didi

ruby - File.open 没有正确记录或者我遗漏了什么?

转载 作者:太空宇宙 更新时间:2023-11-03 17:59:31 24 4
gpt4 key购买 nike

我不确定 Ruby 的 File.open 方法是否没有正确记录,或者我遗漏了什么。

File 类继承自IOopen 方法似乎就是在这里定义的。据我从文档中得知,File 似乎没有覆盖 IOopen 方法的实现。

documentation for FileIO.open 类方法记录为采用数字文件描述符参数,大概是 IO.sysopen 返回的对象。然而,显然未记录的 File.open 方法将只获取一个文件名。

例如,这失败了,根据文档,这是完全正确的:

IO.open('data/actors.list') do |io| 
#...
end

另一方面,这有效:

File.open('data/actors.list') do |io| 
#...
end

问题是,File.open 似乎覆盖了 IO.open 并具有不同的界面,但它没有记录——或者至少没有出现所以。

我错过了什么吗?这是怎么回事?

最佳答案

我没有深入研究为什么 Ruby-Doc.Org 以这种方式显示它(反正我不使用 Ruby-Doc.Org),但这就是 RubyDoc.Info不得不说:

Method: File.open

Defined in: io.c

  • (File) open(filename, mode = "r"[, opt])
  • (File) open(filename[, mode [, perm]][, opt])
  • (Object) open(filename, mode = "r"[, opt]) {|file| … }
  • (Object) open(filename[, mode [, perm]][, opt]) {|file| … }

With no associated block, open is a synonym for File.new. If the optional code block is given, it will be passed file as an argument, and the File object will automatically be closed when the block terminates. In this instance, File.open returns the value of the block.

Overloads:

  • (File) open(filename, mode = "r"[, opt])
    • Returns: (File)
  • (File) open(filename[, mode [, perm]][, opt])
    • Returns: (File)
  • (Object) open(filename, mode = "r"[, opt]) {|file| … }
    • Yields: (file)
    • Returns: (Object)
  • (Object) open(filename[, mode [, perm]][, opt]) {|file| … }
    • Yields: (file)
    • Returns: (Object)

这与文件 io.c in the YARV sources 中的 RDoc 注释匹配:

/*
* Document-method: File::open
*
* call-seq:
* File.open(filename, mode="r" [, opt]) -> file
* File.open(filename [, mode [, perm]] [, opt]) -> file
* File.open(filename, mode="r" [, opt]) {|file| block } -> obj
* File.open(filename [, mode [, perm]] [, opt]) {|file| block } -> obj
*
* With no associated block, <code>open</code> is a synonym for
* <code>File.new</code>. If the optional code block is given, it will
* be passed <i>file</i> as an argument, and the File object will
* automatically be closed when the block terminates. In this instance,
* <code>File.open</code> returns the value of the block.
*/

关于ruby - File.open 没有正确记录或者我遗漏了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7378467/

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