From: Rick DeNatale Date: 2008-02-23T07:44:31+09:00 Subject: Re: Need cohercing a var into a method name On 2/22/08, Phy Prabab wrote: > Hello, > > I need a small bit of help, I am playing with Logger class and ran into a small problem I am not sure how to solve. Namely, I was interested in command line setting of the logging level, however, the passed argument is not accepted as a method name nor can I figure out how to get the arg "coherced" to a string prior to evaluation of the method call. Here is my code: > > when "--debug" > if(DEBUG_LEVELS.include?(arg)) > mylog.level = Logger::arg.to_s > ^^^^^^^^^^^^ > else > puts " "Debug level can be one of DEBUG, INFO, WARN, ERROR, or FATAL." > ..... Logger#level actually takes an integer. Maybe something like this: if Logger::Severity.const_defined?(arg) mylog.level = Logger::Severity.const_get(arg) else puts "Debug level must be one of #{Logger.Severity.constants.join(',')." end -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/