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

ruby-changes:15610

From: tenderlove <ko1@a...>
Date: Wed, 28 Apr 2010 05:40:21 +0900 (JST)
Subject: [ruby-changes:15610] Ruby:r27519 (trunk): * ext/psych/lib/psych/deprecated.rb: adding deprecated object_maker

tenderlove	2010-04-28 05:40:12 +0900 (Wed, 28 Apr 2010)

  New Revision: 27519

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

  Log:
    * ext/psych/lib/psych/deprecated.rb: adding deprecated object_maker
     method,
    * test/psych/test_deprecated.rb: ditto

  Modified files:
    trunk/ext/psych/lib/psych/deprecated.rb
    trunk/test/psych/test_deprecated.rb

Index: ext/psych/lib/psych/deprecated.rb
===================================================================
--- ext/psych/lib/psych/deprecated.rb	(revision 27518)
+++ ext/psych/lib/psych/deprecated.rb	(revision 27519)
@@ -66,6 +66,13 @@
     end if name
     [type, reference]
   end
+
+  def self.object_maker klass, hash
+    warn "#{caller[0]}: object_maker is deprecated" if $VERBOSE
+    klass.allocate.tap do |obj|
+      hash.each { |k,v| obj.instance_variable_set(:"@#{k}", v) }
+    end
+  end
 end
 
 class Object
Index: test/psych/test_deprecated.rb
===================================================================
--- test/psych/test_deprecated.rb	(revision 27518)
+++ test/psych/test_deprecated.rb	(revision 27519)
@@ -199,5 +199,12 @@
       assert_equal 'int', things.first
       assert_equal Object, things.last
     end
+
+    def test_object_maker
+      thing = Psych.object_maker(Object, { 'a' => 'b', 'c' => 'd' })
+      assert_instance_of(Object, thing)
+      assert_equal 'b', thing.instance_variable_get(:@a)
+      assert_equal 'd', thing.instance_variable_get(:@c)
+    end
   end
 end

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

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