win32utils-devel@rubyforge.org
2004-Feb-26 15:08 UTC
[Win32utils-devel] Trivial API question
I know - I like to futz. I''m thinking of changing the way I pass optional arguments. This is from EventLog: # Write an event to the event log # Current way el.report_event( "source" => "foo", "category" => 0x2, "event_id" => 0x3, "data" => "Warning! Danger Will Robinson!", "type" => EventLog::WARN ) # Proposed way el.report_event{ |e| e.source = "foo" e.category = 0x2 e.event_id = 0x3 e.data = "Warning! Danger Will Robinson!" e.type = EventLog::WARN } This looks a little "cleaner" I think and is a bit more Ruby-ish. It would use a yielded struct, which has an advantage over a hash - you can''t pass a bogus key, i.e. builtin validation. What do you think? Or should I just leave it alone? Dan
win32utils-devel@rubyforge.org
2004-Feb-26 19:03 UTC
[Win32utils-devel] Trivial API question
> > I know - I like to futz. I''m thinking of changing the way I pass > optional arguments. This is from EventLog: > > # Write an event to the event log > > # Current way > el.report_event( > "source" => "foo", > "category" => 0x2, > "event_id" => 0x3, > "data" => "Warning! Danger Will Robinson!", > "type" => EventLog::WARN > ) > > # Proposed way > el.report_event{ |e| > e.source = "foo" > e.category = 0x2 > e.event_id = 0x3 > e.data = "Warning! Danger Will Robinson!" > e.type = EventLog::WARN > } > > This looks a little "cleaner" I think and is a bit more Ruby-ish. It > would use a yielded struct, which has an advantage over a hash - you > can''t pass a bogus key, i.e. builtin validation. > > What do you think? Or should I just leave it alone? > > Dan >Let''s provide both ways :) Regards, Park Heesob --MIME Multi-part separator--
win32utils-devel@rubyforge.org
2004-Feb-27 09:59 UTC
[Win32utils-devel] Trivial API question
> -----Original Message----- > From: win32utils-devel-bounces@rubyforge.org > [mailto:win32utils-devel-bounces@rubyforge.org] On Behalf Of > win32utils-devel@rubyforge.org > Sent: Thursday, February 26, 2004 4:54 PM > To: win32utils-devel@rubyforge.org > Subject: Re:[Win32utils-devel] Trivial API question > > > > > > I know - I like to futz. I''m thinking of changing the way I pass > > optional arguments. This is from EventLog: > > > > # Write an event to the event log > > > > # Current way > > el.report_event( > > "source" => "foo", > > "category" => 0x2, > > "event_id" => 0x3, > > "data" => "Warning! Danger Will Robinson!", > > "type" => EventLog::WARN > > ) > > > > # Proposed way > > el.report_event{ |e| > > e.source = "foo" > > e.category = 0x2 > > e.event_id = 0x3 > > e.data = "Warning! Danger Will Robinson!" > > e.type = EventLog::WARN > > } > > > > This looks a little "cleaner" I think and is a bit more > Ruby-ish. It > > would use a yielded struct, which has an advantage over a > hash - you > > can''t pass a bogus key, i.e. builtin validation. > > > > What do you think? Or should I just leave it alone? > > > > Dan > > > Let''s provide both ways :) > > Regards, > > Park HeesobUgh - too much work to maintain. I''m going to pick one and stick with it. Dan