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

rahardi
  • 213
  • 1
  • 5
  • 12
  • 1
    You might want to have a look at this article: http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/. I'll change your tags, since this doesn't seem to have anything to do with Rails. – polarblau Mar 07 '11 at 10:39

1 Answers1

2

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.

RameshVel
  • 64,778
  • 30
  • 169
  • 213