Ruby issues a warning when assigning to already initialized constant.
Unless, of course, you run it with -W0 option.
Gennady.
···
-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Charlie
Sent: Saturday, April 29, 2006 23:58
To: ruby-talk ML
Subject: Re: Constant in Ruby.Mike Fletcher wrote:
> Charlie wrote:
>> I'm new to Ruby programming and I saw this article which
concerns me:
>>
>>
http://www.bitwisemag.com/copy/features/opinion/ruby/ruby_debate.html
>>
>> Don't get me wrong, I love Ruby. But, the idea that a
constant is not
>> a constant is worrying isn't it? Or have I missed
something? Please
>> comment.
>>
>> X = 10
>> Y = "hello world"
>> Z = "hello world"
>>
>> X = 20
>> Y = "byebye" << "abc"
>> myvar = Z << "xyz"
>>
>> puts(X)
>> 20
>> puts(Y)
>> byebyeabc
>> puts(Z)
>> hello worldxyz
>> myvar
>> "hello worldxyz"
>
> It's constant in that you can't reassign a different
instance to the
> same name (try setting X = 10 after you've set it to 20 and
Ruby will
> gripe). The instances themselves may still be mutable (see
> Object#freeze if you want to change that).okay, I just try this:
X = 20
X = 10
puts(X)
10
X.freeze
X = 30
puts(X)
30Sorry, but I find it difficult to understand as I'm new to
it. Would be helpful if you can enlighten me with some
examples. Thanks.--
Posted via http://www.ruby-forum.com/\.