Project

General

Profile

Bug #15515

Updated by lugray (Lisa Ugray) about 3 years ago

When an `OpenStruct` has some attribute `foo`, calling the `foo` method with an argument gives a no method error: 
 ```ruby 
 foo = OpenStruct.new(bar: OpenStuct.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: 
 ```ruby 
 foo = OpenStruct.new(bar: OpenStuct.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.

Back