Project

General

Profile

Actions

Bug #1219

closed

ostruct freeze still not stable

Added by RobertDober (Robert Dober) about 15 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux]
Backport:
[ruby-core:22559]

Description

=begin
Freezing an ostruct still does not inhibit modification as can be seen in the attached test file and in the following example

o = OpenStruct::new :a => 42
OpenStruct.module_eval do def frozen?; nil end end
o.freeze
o.a = 1764

forwarding freeze to the table or a proxy object that has to change on any update seems necessary. Idea Joël VanderWerf!
=end


Files

ostruct.patch (1.26 KB) ostruct.patch The patch for lib/ostruct.rb RobertDober (Robert Dober), 02/27/2009 06:11 AM
test_ostruct.patch (983 Bytes) test_ostruct.patch The patch for test/ostruct/test_ostruct.rb RobertDober (Robert Dober), 02/27/2009 06:11 AM
Actions #1

Updated by RobertDober (Robert Dober) about 15 years ago

=begin
Forget this patch it is a pain, and way to complicated. Your approach was fine, all we have to do is the following:

class OpenStruct
def freeze
@frozen ||= true
super
end
end

and now, in the write access method you have so nicely refactored, just check for @frozen instead of frozen?.

Cheers
Robert
=end

Actions #2

Updated by nobu (Nobuyoshi Nakada) about 15 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r22652.
=end

Actions #3

Updated by RobertDober (Robert Dober) about 15 years ago

=begin
Thank you, very nice solution.

On Fri, Feb 27, 2009 at 6:26 AM, Nobuyoshi Nakada wrote:

Issue #1219 has been updated by Nobuyoshi Nakada.

Status changed from Open to Closed
% Done changed from 0 to 100

Applied in changeset r22652.

http://redmine.ruby-lang.org/issues/show/1219


http://redmine.ruby-lang.org

--
There are some people who begin the Zoo at the beginning, called
WAYIN, and walk as quickly as they can past every cage until they get
to the one called WAYOUT, but the nicest people go straight to the
animal they love the most, and stay there. ~ A.A. Milne (from
Winnie-the-Pooh)

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0