Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Ruby在这行干什么?_Node.js_Ruby_Syntax - Fatal编程技术网

Node.js Ruby在这行干什么?

Node.js Ruby在这行干什么?,node.js,ruby,syntax,Node.js,Ruby,Syntax,我正在尝试将一些软件从Ruby转换为Node.js。我遇到了这个问题,对Ruby到底想做什么感到好奇: // set the files variable this.files = Dir["C:/folder/log/app.log*"] // sort the files by last modified date/time my_dir = this.files.sort_by { |file| File.mtime(file) } // Copy the files. N

我正在尝试将一些软件从Ruby转换为Node.js。我遇到了这个问题,对Ruby到底想做什么感到好奇:

// set the files variable
    this.files = Dir["C:/folder/log/app.log*"]
// sort the files by last modified date/time
    my_dir = this.files.sort_by { |file| File.mtime(file) }
// Copy the files. Not sure what the [-1] is for
    my_dir.each do |filename|
    copy_files(filename, my_dir[-1])

所以我知道他们想把文件复制到一个新目录,但是[-1]在做什么呢?

负索引是相对于数组的末尾,所以
数组[-1]
是数组中的最后一个元素

例如:

a = %w(This is the end)  # => ["This", "is", "the", "end"]
p a[-1]                  # => "end"
p a[-2]                  # => "the"

负索引是相对于数组末尾的,因此
数组[-1]
是数组中的最后一个元素

例如:

a = %w(This is the end)  # => ["This", "is", "the", "end"]
p a[-1]                  # => "end"
p a[-2]                  # => "the"

这是什么?Ruby没有这样的方法。如果
这是来自Rails的,你需要一个Rails标签。我正在从Ruby转换到Node.js。这个特定的代码段是在转换过程中。这是什么?Ruby没有这样的方法。如果
这是来自Rails的,你需要一个Rails标签。我正在从Ruby转换到Node.js。这个特别的片段是转换中期的。太棒了!非常感谢。令人惊叹的!非常感谢。