[#4595] New block syntax — Daniel Amelang <daniel.amelang@...>

I'm really sorry if this isn't the place to talk about this. I've

25 messages 2005/03/21
[#4606] Re: New block syntax — "David A. Black" <dblack@...> 2005/03/21

Hi --

[#4629] Re: New block syntax — "Sean E. Russell" <ser@...> 2005/03/30

On Monday 21 March 2005 16:17, David A. Black wrote:

[#4648] about REXML::Encoding — speakillof <speakillof@...>

Hi.

15 messages 2005/03/31
[#4659] Re: about REXML::Encoding — "Sean E. Russell" <ser@...> 2005/04/04

On Thursday 31 March 2005 09:44, speakillof wrote:

Re: [patch] logger.rb - allowing logger to be innitialized in a single line

From: "Berger, Daniel" <Daniel.Berger@...>
Date: 2005-03-09 21:16:28 UTC
List: ruby-core #4544
> -----Original Message-----
> From: Sam Roberts [mailto:sroberts@uniserve.com] 
> Sent: Wednesday, March 09, 2005 1:57 PM
> To: ruby-core
> Subject: [patch] logger.rb - allowing logger to be 
> innitialized in a single line
> 
> 
> 
> I wanted to do:
> 
>    SomeClass.logger = Logger.new(name, shift_age = 'weekly') 
> { |l| l.level = Logger::ERROR }
> 
> not
> 
>    alogger = Logger.new(name, shift_age = 'weekly')
>    alogger.level = Logger::ERROR
>    SomeClass.logger = alogger

<snip>

Hm...how about this modification?

--- logger.orig	Wed Mar  9 14:03:35 2005
+++ logger.rb	Wed Mar  9 14:02:32 2005
@@ -246,6 +246,8 @@
   # Create an instance.  See Logger::LogDevice.new for more information
if
   # required.
   #
+  attr_accessor :logdev, :shift_age, :shift_size
+  attr_reader :level
   def initialize(logdev, shift_age = 0, shift_size = 1048576)
     @logdev = nil
     @progname = nil
@@ -252,6 +254,7 @@
     @level = DEBUG
     @datetime_format = nil
     @logdev = nil
+    yield self if block_given?
     if logdev
       @logdev = LogDevice.new(logdev, :shift_age => shift_age,
:shift_size => shift_size)
     end

This is similar, but it's a little cleaner I think.  I also provides
accessors for logdev, shift_age and shift_size, as well as a reader for
level, which all appear to be missing.

Regards,

Dan



In This Thread

Prev Next