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
This commit is contained in:
nobu 2015-11-16 09:21:56 +00:00
parent 1ff30ea2b1
commit 20690026a7
6 changed files with 54 additions and 1 deletions

View file

@ -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