From: Aldric Giacomoni Date: 2009-12-17T01:07:15+09:00 Subject: Re: Using threads to show progress Brian Candler wrote: > Aldric Giacomoni wrote: >> That's pretty interesting. Are you.. Defining an instance of the class >> within the class itself ? > > Yes. It's just a shortcut to allow you to use a default instance, whilst > still allowing you to have multiple instances if you want. > >> Why are you using STDERR? > > Just convention really. > > If the rake task generates useful output, the user may have redirected > STDOUT to a file (*). And STDERR is unbuffered by default, so you see > the messages immediately without having to flush. > > (*) Of course, it is possible to redirect stderr too: 2>/dev/null will > silence your progress messages. I see! Very nice. I have one last question. >if __FILE__ == $0 > Progress << "Feeding the cat" > 33.times do |x| > Progress << ["munch", x, 33] > sleep(0.1) > end > Progress << "Put the cat out" > Progress << "Go to sleep" > 20.times do |x| > Progress << ["zzzzzzz", x, 20] > sleep(0.2) > end > Progress << "Wakey wakey!" >end From inside a loop, can I dynamically know over how many elements the loop will iterate? I noticed the repetition of '33' and '20' ... :) -- Posted via http://www.ruby-forum.com/.