Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

brrrrr! freeze is not needed

  • Loading branch information...
commit 9b48a94c0ae1d128d819e2523a813738c1662489 1 parent 5e6382e
@tenderlove tenderlove authored
Showing with 1 addition and 1 deletion.
  1. +1 −1  activerecord/lib/active_record/session_store.rb
View
2  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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ SESSION_RECORD_KEY = 'rack.session.record'
private
def get_session(env, sid)

2 comments on commit 9b48a94

@nicolasblanco

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

@tenderlove
Owner

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
end

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.
Something went wrong with that request. Please try again.