[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: retry does not work

T. Onoma

11/20/2003 11:18:00 AM

> You are raising an exception, this is, for me, different than sending
> message to stdout

okay, i grant you that was not the intention of raise when designed. but a rose by any other name....

so what other means are there? should a raise_message be added? or maybe you are right. maybe my library is "badly designed", but if so then tell me what would the alternative be that achieves such seperation?

-t0

2 Answers

ts

11/20/2003 11:27:00 AM

0

>>>>> "T" == T Onoma <transami@runbox.com> writes:

T> so what other means are there? should a raise_message be added? or maybe
T> you are right. maybe my library is "badly designed", but if so then tell
T> me what would the alternative be that achieves such seperation?

svg% cat b.rb
#!./ruby

def send_message
warn "message"
end

$-w = nil

puts "before"
send_message
puts "after"

class A
def write(string)
puts "a nice message #{string}"
end
end

$stderr = A.new
$-w = true

send_message
svg%


svg% ruby b.rb
before
after
a nice message message
a nice message
svg%



Guy Decoux


Robert Klemme

11/20/2003 12:32:00 PM

0


"T. Onoma" <transami@runbox.com> schrieb im Newsbeitrag
news:E1AMmpA-000682-J5@odie.runbox.com...
> > You are raising an exception, this is, for me, different than sending
> > message to stdout
>
> okay, i grant you that was not the intention of raise when designed. but
a rose by any other name....
>
> so what other means are there? should a raise_message be added? or maybe
you are right. maybe my library is "badly designed", but if so then tell
me what would the alternative be that achieves such seperation?

class Downloader
attr_accessor :state_reporter

def dowload(url)
read_bytes = 0

# open conn

while( chunk = io.read( 1024 ) )
read_bytes += chunk.length
# write bytes to file
self.state_reporter && self.state_reporter.call(url, read_bytes)
end
end
end

d = Downloader.new
d.state_reporter = proc {|url, bytes| puts "read #{bytes} from #{url}"

d.download 'http://foo/bar'

You get the picture...

robert