[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

openstruct / constant negating question

Pugal P

4/16/2007 3:28:00 PM

Hello,
I am a newbie to Ruby. I have a nested hash converted to openstruct
(primarily for ease of access).

PreProduction
webServers
webServer1
webServer2
appServers
appServer1
appServer2 etc.,
I have the following global variables
$RCProperties -> openstruct
$RCPREPROD -> 'PreProduction'
$RCWEBSERVER -> 'webServers'

If I invoke it with $RCProperties.PreProduction.webServers things work
as expected. However when I try to invoke using
$RCProperties.$RCPREPROD.$RCWEBSERVERS ...I am getting syntax error.
Do I need to negate the . using regular expression? If yes, I tried
using $RCProperties\.$RCPreprod\.$RCWEBSERVERS but still getting the
same error message.
Any help would be highly appreciated.

Thanks
Pugal

--
Posted via http://www.ruby-....

2 Answers

Robert Klemme

4/16/2007 3:50:00 PM

0

On 16.04.2007 17:28, Pugal Panneerselvam wrote:
> I am a newbie to Ruby. I have a nested hash converted to openstruct
> (primarily for ease of access).

It seems you made your access more complicated...

> PreProduction
> webServers
> webServer1
> webServer2
> appServers
> appServer1
> appServer2 etc.,
> I have the following global variables
> $RCProperties -> openstruct
> $RCPREPROD -> 'PreProduction'
> $RCWEBSERVER -> 'webServers'
>
> If I invoke it with $RCProperties.PreProduction.webServers things work
> as expected. However when I try to invoke using
> $RCProperties.$RCPREPROD.$RCWEBSERVERS ...I am getting syntax error.
> Do I need to negate the . using regular expression? If yes, I tried
> using $RCProperties\.$RCPreprod\.$RCWEBSERVERS but still getting the
> same error message.

You need to either do

$RCProperties.PreProduction.webServers

or

$RCProperties.send($RCPREPROD).send($RCWEBSERVER)

or revert back to Hashes and do

$RCProperties[$RCPREPROD][$RCWEBSERVER]

Kind regards

robert

Pugal P

4/16/2007 4:05:00 PM

0


It works. Thank you.


--
Posted via http://www.ruby-....