ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Freeze not freezing
by Ralph Shnelvar other posts by this author
Nov 5 2009 6:05AM messages near this date
Re: How do I send referer in get request? | Re: Freeze not freezing
Note that I am new to this list and to Ruby.


Consider ...

irb(main):020:0>  c=[0,1]
=>  [0, 1]
irb(main):021:0>  c[0].freeze
=>  0
irb(main):022:0>  c[0]=2
=>  2
irb(main):023:0>  c
=>  [2, 1]
irb(main):024:0> 


Similarly ...


irb(main):029:0>  f=1
=>  1
irb(main):030:0>  f.freeze
=>  1
irb(main):031:0>  f=2
=>  2




It took a few moments for me to scratch my head and then I thought
that the reason that there was no message when c[0] or f changed was that
c[0] is not an object but a reference to an object (the number 2).

So I searched the archives and it appears taht my reasoning is
correct.  I think.

there was the suggestion to make f a constant, F.  Yes, that generates
a warning ... but it is not what I want.  I want to freeze the
reference as well as the object.

In C++ it is possible to "freeze" (i.e. const) both a pointer to an
object and the object itself.  Is this possible in Ruby?


a) Is my reasoning correct?

b) Is there a way to do what I want? That is, freeze f or c[0] so that
I get some sort of message/error/exception?

c) Do my examples violate POLS?
Thread:
Ralph Shnelvar
Yukihiro Matsumoto
Seebs
Ralph Shnelvar
Jordi Bunster

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved