From: "mhuggins (Matt Huggins)" Date: 2013-03-13T05:55:16+09:00 Subject: [ruby-core:53343] [ruby-trunk - Bug #8078][Open] Once nil is frozen, an unfrozen instance cannot be reached Issue #8078 has been reported by mhuggins (Matt Huggins). ---------------------------------------- Bug #8078: Once nil is frozen, an unfrozen instance cannot be reached https://bugs.ruby-lang.org/issues/8078 Author: mhuggins (Matt Huggins) Status: Open Priority: Normal Assignee: Category: core Target version: ruby -v: ruby 1.9.3p327 (2012-11-10) [i386-mingw32] =begin This is a rather peculiar bug I stumbled across. The basic issue is that once `nil` has been frozen, there is no way to access an unfrozen instance of nil. nil.frozen? => false nil.freeze nil.frozen? => true I say this is a peculiar bug because generally it doesn't matter if `nil` is frozen or not (since it is basically frozen even if not explicitly defined as such). However, since Ruby is based upon duck typing, you might run into a scenario like the following: def get(cache_key) content = Rails.cache.read(cache_key) content.frozen? ? content.dup : content end If I call the above method and the cache key exists, `content` is a frozen string, which I then `dup` to get an unfrozen copy. If I call the above method and the cache key does NOT exist, `content` is a frozen `nil`, which it then attempts to `dup` unsuccessfully since a NilClass instance cannot be duped. =end -- http://bugs.ruby-lang.org/