[前][次][番号順一覧][スレッド一覧]

ruby-changes:40984

From: marcandre <ko1@a...>
Date: Sun, 13 Dec 2015 06:41:20 +0900 (JST)
Subject: [ruby-changes:40984] marcandRe: r53063 (trunk): * lib/ostruct.rb: Have OpenStruct#dig raise if argument is not a symbol

marcandre	2015-12-13 06:40:50 +0900 (Sun, 13 Dec 2015)

  New Revision: 53063

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53063

  Log:
    * lib/ostruct.rb: Have OpenStruct#dig raise if argument is not a symbol
      nor a string. See [#11762]

  Modified files:
    trunk/ChangeLog
    trunk/lib/ostruct.rb
    trunk/test/ostruct/test_ostruct.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53062)
+++ ChangeLog	(revision 53063)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Dec 13 06:40:30 2015  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* 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  <shugo@r...>
 
 	* vm_insnhelper.c (vm_call_method_missing): method_missing should
Index: lib/ostruct.rb
===================================================================
--- lib/ostruct.rb	(revision 53062)
+++ lib/ostruct.rb	(revision 53063)
@@ -227,7 +227,7 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L227
     begin
       name = name.to_sym
     rescue NoMethodError
-      return
+      raise TypeError, "#{name} is not a symbol nor a string"
     end
     @table.dig(name, *names)
   end
Index: test/ostruct/test_ostruct.rb
===================================================================
--- test/ostruct/test_ostruct.rb	(revision 53062)
+++ test/ostruct/test_ostruct.rb	(revision 53063)
@@ -116,7 +116,7 @@ class TC_OpenStruct < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L116
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]