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 | e2384dd69c624555916b1162b0e7f9bd6a8480a4 (patch) | |
tree | c2e21553dc5527199a6caac0588ffb158d9be7dd /test | |
parent | 88757dcb007a8f9106329c85543df1beb321ecab (diff) | |
download | ruby-e2384dd69c624555916b1162b0e7f9bd6a8480a4.tar.gz |
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')
-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 |