From 13d8bb03859255049dd10046a0a1a24352ec8110 Mon Sep 17 00:00:00 2001 From: marcandre Date: Sat, 12 Dec 2015 21:40:50 +0000 Subject: * lib/ostruct.rb: Have OpenStruct#dig raise if argument is not a symbol nor a string. See [#11762] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ lib/ostruct.rb | 2 +- test/ostruct/test_ostruct.rb | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 58b99011b4..d3edb059bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Dec 13 06:40:30 2015 Marc-Andre Lafortune + + * lib/ostruct.rb: Have OpenStruct#dig raise if argument is not a + symbol + nor a string. See [#11762] + Sun Dec 13 00:05:42 2015 Shugo Maeda * vm_insnhelper.c (vm_call_method_missing): method_missing should diff --git a/lib/ostruct.rb b/lib/ostruct.rb index 0e13f40692..84244b3d9e 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -227,7 +227,7 @@ class OpenStruct begin name = name.to_sym rescue NoMethodError - return + raise TypeError, "#{name} is not a symbol nor a string" end @table.dig(name, *names) end diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb index d8d4cd30f0..b098992bc9 100644 --- a/test/ostruct/test_ostruct.rb +++ b/test/ostruct/test_ostruct.rb @@ -116,7 +116,7 @@ class TC_OpenStruct < Test::Unit::TestCase os2.child = [42] assert_equal :bar, os1.dig("child", :foo) assert_nil os1.dig("parent", :foo) - assert_nil os1.dig("child", 0) + assert_raise(TypeError) { os1.dig("child", 0) } end def test_to_h -- cgit v1.2.3