Backport #4578
closedFixnum.freeze not frozen?
Description
=begin
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.
=end
Updated by shyouhei (Shyouhei Urabe) over 13 years ago
=begin
You agree integers are immutable. Immutable objects have no states by definition, OK?
The frozenness is a state. You should not care about.
=end
Updated by judofyr (Magnus Holm) over 13 years ago
=begin
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.org 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/4578Author: 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 :importantdef initialize(important)
@important = important
@important.freeze
end
endDemanding 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.
=end
Updated by matz (Yukihiro Matsumoto) over 13 years ago
- ruby -v changed from ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10.7.0] to -
=begin
Hi,
In message "Re: [ruby-core:35767] Re: [Ruby 1.8 - Bug #4578] Fixnum.freeze not frozen?"
on Fri, 15 Apr 2011 14:31:53 +0900, Magnus Holm judofyr@gmail.com writes:
|Isn't technically all Fixnums "frozen" (because you can't modify the state)?
Not really, since fixnums could have instance variables.
Thus, theoretically, there's room for freezing fixnums. I don't think
it's worth the cost though.
matz.
=end
Updated by headius (Charles Nutter) over 13 years ago
=begin
On Fri, Apr 15, 2011 at 12:37 AM, Yukihiro Matsumoto matz@ruby-lang.org wrote:
Hi,
In message "Re: [ruby-core:35767] Re: [Ruby 1.8 - Bug #4578] Fixnum.freeze not frozen?"
on Fri, 15 Apr 2011 14:31:53 +0900, Magnus Holm judofyr@gmail.com writes:|Isn't technically all Fixnums "frozen" (because you can't modify the state)?
Not really, since fixnums could have instance variables.
Thus, theoretically, there's room for freezing fixnums. I don't think
it's worth the cost though.
I guess you mean the cost in MRI. In JRuby, Fixnums could be frozen
(we don't enable it to match MRI), but the same value is not
guaranteed to be the same object throughout the system. Tradeoffs!
- Charlie
=end
Updated by rbevers (Russell Bevers) over 13 years ago
=begin
BTW, freeze & frozen? work fine on Fixnums in 1.9.x on my platform. I agree that it seems unnecessary to correct in 1.8.x. I can move to 1.9.
=end
Updated by jeremyevans0 (Jeremy Evans) over 5 years ago
- Tracker changed from Bug to Backport
- Project changed from Ruby 1.8 to Backport187
- Description updated (diff)
- Status changed from Open to Closed
- ruby -v deleted (
-)