我需要在 fo 变量中获取文件的路径,以便我可以将路径传递给 unzip_file 函数。我如何在这里获得路径?
url = 'http://www.dtniq.com/product/mktsymbols_v2.zip'
open(url, 'r') do |fo|
puts "unzipfile "
unzip_file(fo, "c:\\temp11\\")
end
就如何做而言,我会这样做:
找出我正在处理的对象的类
ruby-1.9.2-p290 :001 > tmp_file = open('tmp.txt', 'r')
=> #<File:tmp.txt>
ruby-1.9.2-p290 :001 > tmp_file.class
=> File
去查找那个类的文档
谷歌搜索:红宝石文件
返回Class: File ruby-doc.org
=> www.ruby-doc.org/core/classes/File.html
看看方法。有一个叫path
-> 看起来很有趣
如果我现在还没有找到答案
大多数时候1..3
应该可以得到你需要的东西。一旦你学会阅读文档,你就可以更快地做事。它只是试图克服刚开始时进入文档的难度。