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

ruby-changes:42314

From: naruse <ko1@a...>
Date: Tue, 29 Mar 2016 18:52:56 +0900 (JST)
Subject: [ruby-changes:42314] naruse:r54388 (ruby_2_3): merge revision(s) 53395, 53396: [Backport #11901]

naruse	2016-03-29 18:52:51 +0900 (Tue, 29 Mar 2016)

  New Revision: 54388

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

  Log:
    merge revision(s) 53395,53396: [Backport #11901]
    
    * lib/ostruct.rb: Fix new_ostruct_member to correctly avoid
      redefinition [#11901]
    
    * lib/ostruct.rb (freeze): define deferred accessors before
      freezing to get rid of an error when just reading frozen
      OpenStruct.

  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/ChangeLog
    branches/ruby_2_3/lib/ostruct.rb
    branches/ruby_2_3/test/ostruct/test_ostruct.rb
    branches/ruby_2_3/version.h
Index: ruby_2_3/ChangeLog
===================================================================
--- ruby_2_3/ChangeLog	(revision 54387)
+++ ruby_2_3/ChangeLog	(revision 54388)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1
+Tue Mar 29 18:49:54 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.
+
+Tue Mar 29 18:49:54 2016  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* lib/ostruct.rb: Fix new_ostruct_member to correctly avoid
+	  redefinition [#11901]
+
 Tue Mar 29 17:54:17 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/ostruct.rb (OpenStruct): make respond_to? working on
Index: ruby_2_3/lib/ostruct.rb
===================================================================
--- ruby_2_3/lib/ostruct.rb	(revision 54387)
+++ ruby_2_3/lib/ostruct.rb	(revision 54388)
@@ -168,7 +168,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/ostruct.rb#L168
   #
   def new_ostruct_member(name)
     name = name.to_sym
-    unless respond_to?(name)
+    unless singleton_class.method_defined?(name)
       define_singleton_method(name) { @table[name] }
       define_singleton_method("#{name}=") { |x| modifiable[name] = x }
     end
@@ -176,6 +176,11 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/ruby_2_3/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
Index: ruby_2_3/test/ostruct/test_ostruct.rb
===================================================================
--- ruby_2_3/test/ostruct/test_ostruct.rb	(revision 54387)
+++ ruby_2_3/test/ostruct/test_ostruct.rb	(revision 54388)
@@ -164,4 +164,21 @@ class TC_OpenStruct < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ostruct/test_ostruct.rb#L164
     e = assert_raise(ArgumentError) { os.send :foo=, true, true }
     assert_match(/#{__callee__}/, e.backtrace[0])
   end
+
+  def test_accessor_defines_method
+    os = OpenStruct.new(foo: 42)
+    assert os.respond_to? :foo
+    assert_equal([], os.singleton_methods)
+    assert_equal(42, os.foo)
+    assert_equal([:foo, :foo=], os.singleton_methods)
+  end
+
+  def test_does_not_redefine
+    os = OpenStruct.new(foo: 42)
+    def os.foo
+      43
+    end
+    os.foo = 44
+    assert_equal(43, os.foo)
+  end
 end
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 54387)
+++ ruby_2_3/version.h	(revision 54388)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.0"
 #define RUBY_RELEASE_DATE "2016-03-29"
-#define RUBY_PATCHLEVEL 44
+#define RUBY_PATCHLEVEL 45
 
 #define RUBY_RELEASE_YEAR 2016
 #define RUBY_RELEASE_MONTH 3

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r53395-53396


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

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