Gennady Bystritsky
4/7/2008 9:18:00 PM
> -----Original Message-----
> From: I=F1aki Baz Castillo [mailto:ibc@aliax.net]
> Sent: Monday, April 07, 2008 1:40 PM
> To: ruby-talk ML
> Subject: Re: Is possible to define various methods at same time?
>
> El Lunes, 7 de Abril de 2008, Nobuyoshi Nakada escribi=F3:
> > Hi,
> >
> > At Sun, 6 Apr 2008 22:54:52 +0900,
> >
> > I=F1aki Baz Castillo wrote in [ruby-talk:297234]:
> > > Hi, is possible to define various methods in a single declaration?
> > > something as:
> > >
> > > def method1, method2 (args)
> > > ...
> > > end
> > >
> > > Of course the above doesn't work, anyway to do it?
> >
> > Do you want alias?
> >
> > def method1(args)
> > ...
> > end
> > alias method2 method1
>
> I don't think aliases are valid for me since I want each
> method call "super"
> (inheritance):
>
> def debug(log_zone, msg)
> super(formatter(log_zone, msg)) end
> def info(log_zone, msg)
> super(formatter(log_zone, msg)) end
> def warn(log_zone, msg)
> super(formatter(log_zone, msg)) end
> def error(log_zone, msg)
> super(formatter(log_zone, msg)) end
> def fatal(log_zone, msg)
> super(formatter(log_zone, msg)) end
> def unknown(log_zone, msg)
> super(formatter(log_zone, msg)) end
>
> And I want:
>
> def debug,info,war,error,fatal,unknown(log_zone, msg)
> super(formatter(log_zone, msg))
> end
>
> Thanks a lot.
>
>
> --
> I=F1aki Baz Castillo
>
>
How about something like this?
class CustomLogger
def initialize(*args)
@logger =3D Logger.new(*args)
end
def method_missing(name, *args)
case :debug, :info, :warn, :error, :fatal, :unknown
@logger.send name, formatter(*args)
else
@logger.send name, *args
end
end
def formatter(log_zone, msg)
# Do your formatting here
...
end
end
=3DGennady.