From: Gennady Bystritsky Date: 2008-04-08T06:17:57+09:00 Subject: Re: Is possible to define various methods at same time? > -----Original Message----- > From: Iñaki 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ó: > > Hi, > > > > At Sun, 6 Apr 2008 22:54:52 +0900, > > > > Iñaki 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ñaki Baz Castillo > > How about something like this? class CustomLogger def initialize(*args) @logger = 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 =Gennady.