Project

General

Profile

Feature #8906

Freeze Symbols

Added by Koichi Sasada over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
[ruby-core:57179]

Description

Now, Integer and Float objects are frozen objects.
How about to freeze Symbol objects, too?
I think Symbol is friend of Integer.

Current behavior:
p :foo.frozen? #=> false
:foo.instance_variable_set(:@foo, 1)
p :foo.instance_variable_get(:@foo) #=> 1


Background of this proposal:

Now, I'm working on "GC-able Symbols" feature.
Freezing symbols make this feature easier.

for example:
(1) set an instance variable @iv for symbol s
(2) collect s
(3) generate s
(4) what value of @iv for s returns?


Related issues

Related to Ruby trunk - Feature #8579: Frozen string syntax Closed 06/29/2013

Associated revisions

Revision 42974
Added by Koichi Sasada over 2 years ago

  • include/ruby/ruby.h: make Symbol objects frozen. [Feature #8906] I want to freeze this good day, too.
  • test/ruby/test_eval.rb: catch up this change.
  • test/ruby/test_symbol.rb: add a test to check frozen symbols.

Revision 42974
Added by Koichi Sasada over 2 years ago

  • include/ruby/ruby.h: make Symbol objects frozen. [Feature #8906] I want to freeze this good day, too.
  • test/ruby/test_eval.rb: catch up this change.
  • test/ruby/test_symbol.rb: add a test to check frozen symbols.

History

#1 [ruby-core:57180] Updated by Yukihiro Matsumoto over 2 years ago

Symbol is a symbol is a symbol. It's not a string, nor an integer.

Besides that, I agree with making symbols frozen.

Matz.

#2 [ruby-core:57182] Updated by Charles Nutter over 2 years ago

+1. Anything that can't be extended and whose regular state can't be mutated (not counting user-provided instance vars and such) should be frozen.

#3 [ruby-core:57210] Updated by Anonymous over 2 years ago

Cool, I love frozen stuff!

#4 Updated by Koichi Sasada over 2 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r42974.
Koichi, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • include/ruby/ruby.h: make Symbol objects frozen. [Feature #8906] I want to freeze this good day, too.
  • test/ruby/test_eval.rb: catch up this change.
  • test/ruby/test_symbol.rb: add a test to check frozen symbols.

Also available in: Atom PDF