[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: Constant Hash strangeness
From: "Austin Ziegler" <halostatue () gmail ! com>
Date: 2006-05-31 19:47:02
Message-ID: 9e7db9110605311247i7dc639fbue91783c4301b9099 () mail ! gmail ! com
[Download RAW message or body]
On 5/31/06, Wiktor Macura <wmacura@gmail.com> wrote:
> Hello.
>
> This seems to be trivial, yet I can't find an explanation for it
> anywhere online. Apologies if I'm asking the obvious.
>
> If you create a constant hash:
>
> CONSTANTHASH = { :foo => "foobar" }
> x = CONSTANTHASH[:foo]
> x << "-suffix"
> p CONSTANTHASH
>
> One gets the following output:
>
> { :foo => "foobar-suffix" }
> nil
>
> So, this sort of makes sense if one considers that variables in Ruby
> are references. So Ruby only protects the hash, not the values keys in
> the hash point to. But... is there any way to protect the values, and
> not just the keys?
Constants don't work the way that you think they do. I'll be posting
an article about this soon; I just haven't decided where to put it.
-austin
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic