diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-14 13:47:24 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-14 13:47:24 +0000 |
commit | 816c5323fe82a7a4502f35ab8252ed56a6251688 (patch) | |
tree | f8c1d1bc456417a67004edf8d52a1e8483a9baf3 /lib/ostruct.rb | |
parent | 1119bb4794b32fc0edfc95ba12f02bf151c170c5 (diff) |
OpenStruct: improve error message when passing wrong number of arguments.
Patch by Lisa Ugray (issue #15515)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/ostruct.rb')
-rw-r--r-- | lib/ostruct.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/ostruct.rb b/lib/ostruct.rb index a758a65979..c3b0546d5f 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -213,7 +213,7 @@ class OpenStruct len = args.length if mname = mid[/.*(?==\z)/m] if len != 1 - raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1) + raise ArgumentError, "wrong number of arguments (given #{len}, expected 1)", caller(1) end modifiable?[new_ostruct_member!(mname)] = args[0] elsif len == 0 # and /\A[a-z_]\w*\z/ =~ mid # @@ -221,6 +221,8 @@ class OpenStruct new_ostruct_member!(mid) unless frozen? @table[mid] end + elsif @table.key?(mid) + raise ArgumentError, "wrong number of arguments (given #{len}, expected 0)" else begin super |