From 770ddcdfe069f8654a07e0fcc758aea591cdd17d Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 24 Apr 2012 03:46:55 +0000 Subject: * hash.c, object.c, struct.c, lib/ostruct.rb: add to_h methods. [Feature #6276] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ostruct/test_ostruct.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/ostruct/test_ostruct.rb') diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index dca2382b2b..1826e40e53 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -73,4 +73,16 @@ class TC_OpenStruct < Test::Unit::TestCase assert_raise(NoMethodError) { o[:foo] } end + def test_to_h + h = {name: "John Smith", age: 70, pension: 300} + os = OpenStruct.new(h) + to_h = os.to_h + assert_equal(h, to_h) + + to_h[:age] = 71 + assert_equal(70, os.age) + assert_equal(70, h[:age]) + + assert_equal(h, OpenStruct.new("name" => "John Smith", "age" => 70, pension: 300).to_h) + end end -- cgit v1.2.3