1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
tenderlove 2010-04-27 20:40:12 +00:00
parent ad3c1061a7
commit 430e0ce491
2 changed files with 14 additions and 0 deletions

View file

@ -66,6 +66,13 @@ module Psych
end if name end if name
[type, reference] [type, reference]
end 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 end
class Object class Object

View file

@ -199,5 +199,12 @@ module Psych
assert_equal 'int', things.first assert_equal 'int', things.first
assert_equal Object, things.last assert_equal Object, things.last
end 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
end end