简体   繁体   中英

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| . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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