mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 17:14:01 +02:00
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:
parent
1ff30ea2b1
commit
20690026a7
6 changed files with 54 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue