diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-16 09:21:56 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-16 09:21:56 +0000 |
commit | 20690026a7dd7622c7d824de71e337a68a293b63 (patch) | |
tree | c2e21553dc5527199a6caac0588ffb158d9be7dd /test/ruby/test_struct.rb | |
parent | 1ff30ea2b1675fa6bfa50bb5bac1f8cdea8524e1 (diff) |
struct.c: dig
* object.c (rb_obj_dig): dig in nested structs too.
* struct.c (rb_struct_dig): new method Struct#dig.
[Feature #11688]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_struct.rb')
-rw-r--r-- | test/ruby/test_struct.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index f51432cfd6..780d344b8e 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -353,6 +353,13 @@ module TestStruct assert_equal "[Bug #9353]", x.send(:a=, "[Bug #9353]") end + def test_dig + klass = @Struct.new(:a) + o = klass.new(klass.new({b: [1, 2, 3]})) + assert_equal(1, o.dig(:a, :a, :b, 0)) + assert_nil(o.dig(:b, 0)) + end + class TopStruct < Test::Unit::TestCase include TestStruct |