From: Magnus Holm Date: 2011-04-15T14:31:53+09:00 Subject: [ruby-core:35767] Re: [Ruby 1.8 - Bug #4578] Fixnum.freeze not frozen? --0016364ee01ed39b1704a0ee5b02 Content-Type: text/plain; charset=UTF-8 Isn't technically all Fixnums "frozen" (because you can't modify the state)? // Magnus Holm On Fri, Apr 15, 2011 at 02:34, wrote: > > Issue #4578 has been updated by Shyouhei Urabe. > > > You agree integers are immutable. Immutable objects have no states by > definition, OK? > > The frozenness is a state. You should not care about. > ---------------------------------------- > Bug #4578: Fixnum.freeze not frozen? > http://redmine.ruby-lang.org/issues/4578 > > Author: Russell Bevers > Status: Open > Priority: Normal > Assignee: > Category: > Target version: > ruby -v: ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10.7.0] > > > Using ruby 1.8.7 p334 > > a = 5; a.freeze > > Expect: true == a.frozen? > Result: false == a.frozen? > > I realize Fixnum is already immutable, however consider the following code: > > class Demanding > attr_reader :important > > def initialize(important) > @important = important > @important.freeze > end > end > > Demanding wants to be able to rely on identifier not changing over its > lifespan. I could make it demanding with some other mechanism such as: > * Force important to be a particular type > * Force important to respond_to? particular messages during initialization > > These are all slippery and don't address the concern of mutability of > important objects. Freeze seemed like the obvious solution, but it's > probably best for me to just take a deep copy of important for Demanding's > own use. > > In the meantime, I thought I should share that freeze is not working for > all objects in Ruby 1.8.7 p334. > > > -- > http://redmine.ruby-lang.org > > --0016364ee01ed39b1704a0ee5b02 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Isn't technically all Fixnums "frozen" (because you can't= modify the state)?

// Magnus Holm


On Fri, Apr 15, 2011 at 02:34, <redmine@ruby-lang.or= g> wrote:

Issue #4578 has been updated by Shyouhei Urabe.


You agree integers are immutable. =C2=A0Immutable objects have no states by= definition, OK?

The frozenness is a state. =C2=A0You should not care about.
----------------------------------------<= br> Bug #4578: Fixnum.freeze not frozen?
http= ://redmine.ruby-lang.org/issues/4578

Author: Russell Bevers
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10.7.0]


Using ruby 1.8.7 p334

a =3D 5; a.freeze

Expect: =C2=A0true =3D=3D a.frozen?
Result: =C2=A0false =3D=3D a.frozen?

I realize Fixnum is already immutable, however consider the following code:=

class Demanding
=C2=A0 =C2=A0attr_reader :important

=C2=A0 =C2=A0def initialize(important)
=C2=A0 =C2=A0 =C2=A0 =C2=A0@important =3D important
=C2=A0 =C2=A0 =C2=A0 =C2=A0@important.freeze
=C2=A0 =C2=A0end
end

Demanding wants to be able to rely on identifier not changing over its life= span. =C2=A0I could make it demanding with some other mechanism such as: =C2=A0* Force important to be a particular type
=C2=A0* Force important to respond_to? particular messages during initializ= ation

These are all slippery and don't address the concern of mutability of i= mportant objects. =C2=A0Freeze seemed like the obvious solution, but it'= ;s probably best for me to just take a deep copy of important for Demanding= 's own use.

In the meantime, I thought I should share that freeze is not working for al= l objects in Ruby 1.8.7 p334.


--
http://redmine.r= uby-lang.org


--0016364ee01ed39b1704a0ee5b02--