From: Matt Armstrong Date: 2004-11-22T16:07:44+09:00 Subject: Re: assert Gavin Sinclair writes: > On Sunday, November 21, 2004, 3:48:08 PM, itsme213 wrote: [...] >>> The other contexts that assert() should support are: >>> - production => throw an exception >>> - debugging => start an irb session >>> - custom => invoke some user provided assert failure handler > >> I like this the best of all I've seen so far. > > This is a good idea to an extent. I doubt how much it would be used > in practice. To me, the use-cases for production and debugging are > so different that the same code can't serve them both. [...] > require 'assumptions' > > Assumptions.configure do |a| > a.in_debug { start_irb } > a.in_production { throw_exception } > a.custom { ... } > end > > Assumptions.current_mode = :debug [...] > Why not create something like this called Assumptions? Then use the > top-level "assume" method everywhere. If it's good, I'll include it > in dev-utils, because it's obviously a good fit. But I have no > interest in creating it myself: it sounds a lot more useful in > theory than in practice. I doubt I would ever use this. If I want production code throwing exceptions, I will either explicitly code the call to raise with an appropriate exception class or let the built in class do it (array bounds, etc.). I wouldn't want generic "assertion failed" exceptions being thrown. -- matt