Bug #4179

OpenStruct#method_missing handles #[]= wrongly

Added by Caius Durling over 3 years ago. Updated almost 3 years ago.

[ruby-core:33792]
Status:Closed
Priority:Normal
Assignee:-
Category:lib
Target version:1.9.3
ruby -v:ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] Backport:

Description

=begin
## Code to reproduce:

 require "ostruct"
 OpenStruct.new[:foo] = true

## Expected

NoMethodError to be raised, as OpenStruct#[]= is not a defined method.

## Actual

wrong number of arguments (2 for 1) (ArgumentError)

## Notes

I wrote a test case to check that it would raise NoMethodError when you call OpenStruct#[]=, and then amended OpenStruct#method_missing to fix the bug. Patch attached with both test case (including a check that OpenStruct#[] raises a NoMethodError too) and the fix in it.
=end

ostruct_square_bracket_equals.patch Magnifier - Test case for []= and [], and fix for []= bug (977 Bytes) Caius Durling, 12/21/2010 08:40 AM

Associated revisions

Revision 31753
Added by Marc-Andre Lafortune almost 3 years ago

  • lib/ostruct.rb (method_missing): Handle [] and []= correctly. Based on a patch by Caius Durling, bug #4179

History

#1 Updated by Caius Durling over 3 years ago

=begin
On 20 Dec 2010, at 23:43, Caius Durling wrote:

Bug #4179: OpenStruct#method_missing handles #[]= wrongly
http://redmine.ruby-lang.org/issues/show/4179

Erm, not quite sure why reloading the redmine page triggered another notification about the ticket to be sent to the list. Apologies about that.

C


Caius Durling
caius@caius.name
+44 (0) 7960 268 100
http://caius.name/

On 20 Dec 2010, at 23:43, Caius Durling wrote:Bug #4179: OpenStruct#method_missing handles #[]= wronglyhttp://redmine.ruby-lang.org/issues/show/4179Erm, not quite sure why reloading the redmine page triggered another notification about the ticket to be sent to the list. Apologies about that.C---Caius Durlingcaius@caius.name+44 (0) 7960 268 100http://caius.name/
=end

#2 Updated by Marc-Andre Lafortune almost 3 years ago

  • Project changed from Ruby 1.8 to ruby-trunk
  • Category changed from lib to lib
  • Target version deleted (Ruby 1.8.7)

#3 Updated by Marc-Andre Lafortune almost 3 years ago

  • Status changed from Open to Closed
  • Target version set to 1.9.3
  • % Done changed from 0 to 100

Thanks for the patch.
It was modified so that:
- s[] also raises an error
- s[1]=2 states that "[]=" is the missing method (not "[]")

Applied as r31753, RubySpec updated as 9d36c78

Also available in: Atom PDF