Actions
Bug #2221
closedlib/delegate: freeze has odd effects
Description
=begin
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.
=end
Actions
Like0
Like0Like0Like0