Project

General

Profile

Actions

Bug #2221

closed

lib/delegate: freeze has odd effects

Added by marcandre (Marc-Andre Lafortune) about 15 years ago. Updated over 13 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.2dev (2009-10-13 trunk 25317) [x86_64-darwin10.0.0]
Backport:
[ruby-core:26118]

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


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #2679: rubyspec: SimpleDelegator when frozen creates a frozen clone ERRORClosednobu (Nobuyoshi Nakada)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0