PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Need cohercing a var into a method name
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Need cohercing a var into a method name

Réponse
 
LinkBack Outils de la discussion
Vieux 22/02/2008, 22h14   #1
Phy Prabab
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Need cohercing a var into a method name

[Note: parts of this message were removed to make it a legal post.]

Hello,

I need a small bit of , 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.yahoo.com/r/hs
  Réponse avec citation
Vieux 22/02/2008, 22h28   #2
Rob Biedenharn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need cohercing a var into a method name

On Feb 22, 2008, at 5:14 PM, Phy Prabab wrote:
> Hello,
>
> I need a small bit of , 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://agileconsultingllc.com
Rob@AgileConsultingLLC.com


  Réponse avec citation
Vieux 22/02/2008, 22h44   #3
Rick DeNatale
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need cohercing a var into a method name

On 2/22/08, Phy Prabab <phyprabab@yahoo.com> wrote:
> Hello,
>
> I need a small bit of , 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/

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h13.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09353 seconds with 11 queries