зеркало из https://github.com/github/ruby.git
* 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:
Родитель
ad3c1061a7
Коммит
430e0ce491
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче