Project

General

Profile

Bug #15515

OpenStruct raising NoMethodError instead of ArgumentError

Added by lugray (Lisa Ugray) 6 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.7.0dev (2019-01-07 trunk 66747) [x86_64-darwin18]
[ruby-core:90918]

Description

When an OpenStruct has some attribute foo, calling the foo method with an argument gives a no method error:

foo = OpenStruct.new(bar: 'baz')
foo.bar(0) # => NoMethodError (undefined method `bar' for #<OpenStruct bar="baz">)

This is confusing, since foo.respond_to?(:bar) # => true. I would expect:

foo = OpenStruct.new(bar: 'baz')
foo.bar(0) # => ArgumentError (wrong number of arguments (given 1, expected 0))

The included fixes this, and adjusts the arity ArgumentError for the setter to be in line with the default arity messaging too.


Files

Associated revisions

Revision 816c5323
Added by marcandre (Marc-Andre Lafortune) 3 months ago

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

Revision 67556
Added by marcandre (Marc-Andre Lafortune) 3 months ago

OpenStruct: improve error message when passing wrong number of arguments.

Patch by Lisa Ugray (issue #15515)

History

Updated by devpolish (Nardo Nykolyszyn) 6 months ago

Did you mean? OpenStruct

#3

Updated by lugray (Lisa Ugray) 6 months ago

  • Description updated (diff)

Updated by lugray (Lisa Ugray) 6 months ago

devpolish (Nardo Nykolyszyn) wrote:

Did you mean? OpenStruct

Yes, thanks, fixed.

Updated by marcandre (Marc-Andre Lafortune) 3 months ago

  • Assignee set to marcandre (Marc-Andre Lafortune)

Sorry I missed this.

I'm positive on this patch and will commit it shortly unless there's any objection.

Updated by marcandre (Marc-Andre Lafortune) 3 months ago

  • Status changed from Open to Closed

Merged. Thank you for your contribution!

Also available in: Atom PDF