From: Julian Leviston Date: 2008-04-09T09:36:25+09:00 Subject: Re: Is possible to define various methods at same time? What you probably want is this: class CustomLogger < Logger %w(debug info warn error fatal unknown).each do |msg| eval("def #{msg}(log_zone, msg)\n super(formatter(log_zone, msg)) \n end\n") end end Juilan. Learn Ruby on Rails! Check out the FREE VIDS (for a limited time) VIDEO #3 out NOW! http://sensei.zenunit.com/ On 08/04/2008, at 6:38 AM, Iñaki Baz Castillo wrote: > El Lunes, 7 de Abril de 2008, Robert Klemme escribió: > >> Can you explain why you need this? Maybe there is a different >> solution altogether. This redundancy in method definitions is >> irritating to me and I suspect there might be a better way to achieve >> what you really need. > > Thanks a lot. Finally it was not so important for me as I thought > initially, > so I can avoid using it. I asked that for the following reason: > > I'm using CusomLogger class that inherits from Logger class. And I > want to > modify some methods, all exactly the same: > > 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 > > As you can see, all the methods body is exactly the same. I expected > there > could be a cool way to do something as: > > def debug,info,war,error,fatal,unknown(log_zone, msg) > super(formatter(log_zone, msg)) > end > > just it. > > Thanks a lot for your help. > > > > > -- > Iñaki Baz Castillo >