-2

我正在尝试将 2 个空数组传递给一个方法,但我得到一个参数异常......我阅读了一遍,但仍然无法弄清楚为什么会发生这种情况......

代码:

file = File.read("place_code.google.com")
paths = []
urls = []

def parseLog(file, paths)
    file.each_line do |line|
        match = line.match(/([a-z0-9]*GET\s)(.*puzzle\S*)/)
        if match 
            paths << match[2] 
        end
    end
    return paths
end

错误:

:in `parseLog': wrong number of arguments (0 for 2) (ArgumentError)
4

1 回答 1

1

当您调用您的方法时,您没有传入所需的参数。要调用您的方法,您可以执行以下操作:

file = File.read("place_code.google.com")
paths = []
urls = []
class NewClass
     def initalize
     end
     def parseLog(file, paths)
        file.each_line do |line|
          match = line.match(/([a-z0-9]*GET\s)(.*puzzle\S*)/)
          if match 
            paths << match[2] 
          end
       end
      return paths
     end
  end
yourClass = NewClass.new()
yourClass.parseLog(file, path)
于 2013-02-27T16:38:25.383 回答