Actions
Bug #15515
closedOpenStruct raising NoMethodError instead of ArgumentError
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
Updated by lugray (Lisa Ugray) almost 6 years ago
Updated by devpolish (Nardo Nykolyszyn) almost 6 years ago
Did you mean? OpenStruct
Updated by lugray (Lisa Ugray) almost 6 years ago
devpolish (Nardo Nykolyszyn) wrote:
Did you mean? OpenStruct
Yes, thanks, fixed.
Updated by marcandre (Marc-Andre Lafortune) over 5 years 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) over 5 years ago
- Status changed from Open to Closed
Merged. Thank you for your contribution!
Actions
Like0
Like0Like0Like0Like0Like0Like0