开发者

rubyzip coaching

    Zip::ZipOutputStream.open(folderpath) do |z|
        z.print IO.read(folderpath)

In the code above, I have Zip::ZipOutputStream.ope开发者_开发百科n(file_path) do |z|. I do not understand, what the do |z| mean? What does |z| refer to? Can I for example change |z| to other, example is |changez| ?

I got the complete code here http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/ but I can not undestand the 1st line of do |z| .


whatever comes inside ||, considered to be the parameters for the anonymous method (or lambda expression) that comes next,

for ex:

  (1..3).each do |n|
       puts n
  end

can be rewritten as

  (1..3).each {|n| puts n}

|n| could be anything, just a name for a variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜