[前][次][番号順一覧][スレッド一覧]

ruby-changes:41324

From: nobu <ko1@a...>
Date: Fri, 1 Jan 2016 03:27:06 +0900 (JST)
Subject: [ruby-changes:41324] nobu:r53396 (trunk): ostruct.rb: deferred accessors

nobu	2016-01-01 03:26:46 +0900 (Fri, 01 Jan 2016)

  New Revision: 53396

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53396

  Log:
    ostruct.rb: deferred accessors
    
    * lib/ostruct.rb (freeze): define deferred accessors before
      freezing to get rid of an error when just reading frozen
      OpenStruct.

  Modified files:
    trunk/ChangeLog
    trunk/lib/ostruct.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53395)
+++ ChangeLog	(revision 53396)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jan  1 03:26:44 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/ostruct.rb (freeze): define deferred accessors before
+	  freezing to get rid of an error when just reading frozen
+	  OpenStruct.
+
 Thu Dec 31 14:36:45 2015  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* lib/ostruct.rb: Fix new_ostruct_member to correctly avoid
Index: lib/ostruct.rb
===================================================================
--- lib/ostruct.rb	(revision 53395)
+++ lib/ostruct.rb	(revision 53396)
@@ -176,6 +176,11 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L176
   end
   protected :new_ostruct_member
 
+  def freeze
+    @table.each_key {|key| new_ostruct_member(key)}
+    super
+  end
+
   def respond_to_missing?(mid, include_private = false)
     mname = mid.to_s.chomp("=").to_sym
     @table.key?(mname) || super

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]