From: "Ara.T.Howard" Date: 2004-08-06T03:31:27+09:00 Subject: Re: Macros in Ruby On Fri, 6 Aug 2004, Austin Ziegler wrote: > On Fri, 6 Aug 2004 01:31:28 +0900, Ara.T.Howard wrote: >> i actually use them quite a bit and would appreciate a shortcut. i sometimes >> prefer to have modifiable Proc attributes of object to parameterize their >> behaviour rather than messing with inheritence or dynamic redefinition. i >> also end up writing methods which take options callbacks for >> debugging/logging, eg: > > I'd do this as: > > def long_db_update(arg, callback = nil) > sql = gen_sql(arg) > > callback.pre(sql) if callback.respond_to?(:pre) > > res = > if callback.respond_to?(:pan) > t = Thread.new(Thread.current) do |c| > begin > execute(sql) > rescue => e > c.raise (e) > end > end > > loop do > break unless t.status > callback.pan(get_state) > sleep 0.42 > end > > t.join > t.value > else > execute(sql) > end > > callback.post(res) if callback.respond_to?(:post) > res > end > > Then I can create my callback object. With this, I could easily plug > in a debug object (predefined), a GUI object, or anything else, and > my callback becomes part of my defined API. (I would actually even > go as far as modifying callback.post so that its return may > optionally modify res.) > > -austin > -- > Austin Ziegler * halostatue@gmail.com > * Alternate: austin@halostatue.ca > ducktype madness! ;-) sure, that's alot better than my way - i'm just pointing out that some of us type 'l-a-m-b-d-a' alot and consider them an undervalued technique for creating flexible objects since they may easily blur the line between attributes and behaviour (not that ruby is lacking in flexibility!). cheers. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================