# Openstruct / constant negating question

**URL:** <https://www.ruby-forum.com/t/openstruct-constant-negating-question/92149>\
**Category:** Ruby\
**Created:** [April 16, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/openstruct-constant-negating-question/92149 "2007-04-16T17:28:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pugalp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pugalp](https://www.ruby-forum.com/u/pugalp)\
**Post date:** [April 16, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/openstruct-constant-negating-question/92149/1 "2007-04-16T17:28:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pugalp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pugalp](https://www.ruby-forum.com/u/pugalp)\
**Post date:** [April 16, 2007, 5:51pm UTC](https://www.ruby-forum.com/t/openstruct-constant-negating-question/92149/2 "2007-04-16T17:51:06Z")

</div>

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…

> $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

---

<div class="post-metadata">

**Author:** ![pugalp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pugalp](https://www.ruby-forum.com/u/pugalp)\
**Post date:** [April 16, 2007, 6:05pm UTC](https://www.ruby-forum.com/t/openstruct-constant-negating-question/92149/3 "2007-04-16T18:05:05Z")

</div>

It works. Thank you.
