Project

General

Profile

Bug #15515

OpenStruct raising NoMethodError instead of ArgumentError

Added by lugray (Lisa Ugray) about 1 month ago. Updated about 1 month ago.

Status:
Open
Priority:
Normal
Assignee:
-
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

History

Updated by devpolish (Nardo Nykolyszyn) about 1 month ago

Did you mean? OpenStruct

#3

Updated by lugray (Lisa Ugray) about 1 month ago

  • Description updated (diff)

Updated by lugray (Lisa Ugray) about 1 month ago

devpolish (Nardo Nykolyszyn) wrote:

Did you mean? OpenStruct

Yes, thanks, fixed.

Also available in: Atom PDF