Browse files

brrrrr! freeze is not needed

  • Loading branch information...
tenderlove committed Jul 23, 2010
1 parent 5e6382e commit 9b48a94c0ae1d128d819e2523a813738c1662489
Showing with 1 addition and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/session_store.rb
@@ -287,7 +287,7 @@ def destroy
cattr_accessor :session_class
self.session_class = Session
- SESSION_RECORD_KEY = 'rack.session.record'.freeze

rsteckroth Jul 24, 2010

This seems like it prevents the developer or apps from modifying it. I don't see a valid reason here, other than expecting an immutable type.

+ SESSION_RECORD_KEY = 'rack.session.record'
def get_session(env, sid)

2 comments on commit 9b48a94


nicolasblanco replied Jul 23, 2010

just for my ruby culture, when should a ruby constant be freezed and when not? thanks.


tenderlove replied Jul 24, 2010

Even freezing the string does not prevent a developer from modifying what the constant points to. It merely prevents people from modifying that string, not what the constant refers to. For example:

class Foo
  BAR = "blah blah".freeze

Foo::BAR << "hello"             # This raises an exception!
Foo.const_set(:BAR, "INTERNET") # This does not
p Foo::BAR

The value of the constant "BAR" in the Foo class can be changed regardless of the "freeze" call. Calling freeze actually buys us nothing but spending more time when the ruby file is evaluated.

Please sign in to comment.