简体   繁体   English

rubyzip教练

[英]rubyzip coaching

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

In the code above, I have Zip::ZipOutputStream.open(file_path) do |z| 在上面的代码中,我有Zip::ZipOutputStream.open(file_path) do |z| . I do not understand, what the do |z| 我不明白,做什么|z| mean? 意思? What does |z| 什么是| z | refer to? 参考? Can I for example change |z| 我可以改变| z | to other, example is |changez| 对其他人来说,例子是| 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| 我在这里得到了完整的代码http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/但是我无法找到第一行do | z | .

whatever comes inside || 无论内心如何|| , considered to be the parameters for the anonymous method (or lambda expression) that comes next, ,被认为是接下来的匿名方法(或lambda表达式)的参数,

for ex: 对于前:

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

can be rewritten as 可以改写为

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

|n| | N | could be anything, just a name for a variable. 可以是任何东西,只是变量的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM