From 430e0ce4913ad868d8c60ba3e5a0936d0f47af72 Mon Sep 17 00:00:00 2001 From: tenderlove Date: Tue, 27 Apr 2010 20:40:12 +0000 Subject: * ext/psych/lib/psych/deprecated.rb: adding deprecated object_maker method, * test/psych/test_deprecated.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/psych/lib/psych/deprecated.rb | 7 +++++++ test/psych/test_deprecated.rb | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/ext/psych/lib/psych/deprecated.rb b/ext/psych/lib/psych/deprecated.rb index dd4ca6b68f..f4034e32c0 100644 --- a/ext/psych/lib/psych/deprecated.rb +++ b/ext/psych/lib/psych/deprecated.rb @@ -66,6 +66,13 @@ module Psych 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 diff --git a/test/psych/test_deprecated.rb b/test/psych/test_deprecated.rb index 2312600ac8..a272db2332 100644 --- a/test/psych/test_deprecated.rb +++ b/test/psych/test_deprecated.rb @@ -199,5 +199,12 @@ module Psych 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 -- cgit v1.2.3