Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Need cohercing a var into a method name
Phy Prabab
2/22/2008 10:14:00 PM
[Note: parts of this message were removed to make it a legal post.]
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."
.....
(hi-lited is the code segment in question)
I am using GetoptLong to do the cmd line processing. The error given by ruby is:
test.rb:136 undefined method `arg' for Logger:Class (NoMethodError)
...
TIA,
Phy
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yaho...
2 Answers
Rob Biedenharn
2/22/2008 10:29:00 PM
0
On Feb 22, 2008, at 5:14 PM, 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."
> .....
> (hi-lited is the code segment in question)
> I am using GetoptLong to do the cmd line processing. The error
> given by ruby is:
> test.rb:136 undefined method `arg' for Logger:Class (NoMethodError)
> ...
>
> TIA,
> Phy
Logger.const_get(arg)
-Rob
Rob Biedenharn
http://agileconsult...
Rob@AgileConsultingLLC.com
Rick DeNatale
2/22/2008 10:45:00 PM
0
On 2/22/08, Phy Prabab <phyprabab@yahoo.com> 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.denh...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Need cohercing a var into a method name
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password