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

ruby-changes:41294

From: nobu <ko1@a...>
Date: Tue, 29 Dec 2015 12:48:42 +0900 (JST)
Subject: [ruby-changes:41294] nobu:r53366 (trunk): ostruct.rb: respond_to?

nobu	2015-12-29 12:48:36 +0900 (Tue, 29 Dec 2015)

  New Revision: 53366

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

  Log:
    ostruct.rb: respond_to?
    
    * lib/ostruct.rb (OpenStruct): make respond_to? working on
      just-allocated objects for workaround of Psych.
      [ruby-core:72501] [Bug #11884]

  Modified files:
    trunk/ChangeLog
    trunk/lib/ostruct.rb
    trunk/test/ostruct/test_ostruct.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53365)
+++ ChangeLog	(revision 53366)
@@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec 29 12:48:34 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/ostruct.rb (OpenStruct): make respond_to? working on
+	  just-allocated objects for workaround of Psych.
+	  [ruby-core:72501] [Bug #11884]
+
+Tue Dec 29 12:46:13 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/ostruct.rb (OpenStruct): make respond_to? working on
+	  just-allocated objects for workaround of Psych.
+	  [ruby-core:72501] [Bug #11884]
+
 Tue Dec 29 10:35:00 2015  Kenta Murata  <mrkn@m...>
 
 	* test/mkmf/test_have_func.rb (test_have_func):
Index: lib/ostruct.rb
===================================================================
--- lib/ostruct.rb	(revision 53365)
+++ lib/ostruct.rb	(revision 53366)
@@ -71,6 +71,11 @@ https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L71
 # of these properties compared to using a Hash or a Struct.
 #
 class OpenStruct
+  # :nodoc:
+  class << self
+    alias allocate new
+  end
+
   #
   # Creates a new OpenStruct object.  By default, the resulting OpenStruct
   # object will have no attributes.
Index: test/ostruct/test_ostruct.rb
===================================================================
--- test/ostruct/test_ostruct.rb	(revision 53365)
+++ test/ostruct/test_ostruct.rb	(revision 53366)
@@ -23,6 +23,10 @@ class TC_OpenStruct < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L23
     assert_respond_to(o, :a=)
   end
 
+  def test_respond_to_allocated
+    assert_not_respond_to(OpenStruct.allocate, :a)
+  end
+
   def test_equality
     o1 = OpenStruct.new
     o2 = OpenStruct.new

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

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