Bug #2221: lib/delegate: freeze has odd effects
http://redmine.ruby-lang.org/issues/show/2221

Author: Marc-Andre Lafortune
Status: Open, Priority: Low
Category: lib, Target version: 1.9.2
ruby -v: ruby 1.9.2dev (2009-10-13 trunk 25317) [x86_64-darwin10.0.0]

Freeze doesn't quite freeze, and can't be cloned:

require 'delegate'
d = SimpleDelegator.new([1,2,3])
d.freeze
d[0] = :hello; d # ==> [:hello, 2, 3], I expected a runtime error
d.clone # ==> RuntimeError, I expected some kind of copy of d


Maybe #freeze and #frozen should be forwarded:

diff --git a/lib/delegate.rb b/lib/delegate.rb
index 57c479c..f4bd453 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -115,7 +115,7 @@
 # implementation, see SimpleDelegator.
 #
 class Delegator
-  [:to_s,:inspect,:=~,:!~,:===].each do |m|
+  [:to_s,:inspect,:=~,:!~,:===, :freeze, :frozen?].each do |m|
     undef_method m
   end



But maybe the Delegator itself should also be frozen? I mean should a call to #__setobj__ raise a runtime error or not?

Also, there are other methods that should probably be forwarded (eql?, hash, etc...); see issue #1333.


----------------------------------------
http://redmine.ruby-lang.org