summaryrefslogtreecommitdiff
path: root/test/ostruct
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-17 05:36:03 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-17 05:36:03 +0000
commit482530680c18ea2e44c3300c6f323fabc3bd55f7 (patch)
treeb7df8edab6d18d9c8b26a611619a31b12f8a45d7 /test/ostruct
parent66e2139b1a668681e63422cff57ddc2c36859b94 (diff)
OpenStruct#dig
* lib/ostruct.rb (dig): Implement OpenStruct#dig [Feature #11688] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ostruct')
-rw-r--r--test/ostruct/test_ostruct.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb
index 2e8fc7bf58..d8d4cd30f0 100644
--- a/test/ostruct/test_ostruct.rb
+++ b/test/ostruct/test_ostruct.rb
@@ -108,6 +108,17 @@ class TC_OpenStruct < Test::Unit::TestCase
assert_equal :bar, os['foo']
end
+ def test_dig
+ os1 = OpenStruct.new
+ os2 = OpenStruct.new
+ os1.child = os2
+ os2.foo = :bar
+ os2.child = [42]
+ assert_equal :bar, os1.dig("child", :foo)
+ assert_nil os1.dig("parent", :foo)
+ assert_nil os1.dig("child", 0)
+ end
+
def test_to_h
h = {name: "John Smith", age: 70, pension: 300}
os = OpenStruct.new(h)