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?
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?
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%
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}”