Project

General

Profile

Actions

Bug #9448

closed

Assignment with overridden []= returns return value of method rather than new value

Added by Sirupsen (Simon Eskildsen) about 10 years ago. Updated about 10 years ago.

Status:
Closed
Assignee:
-
Target version:
[ruby-core:60071]

Description

When calling []= the assignment will return the return value of the []= method, rather than the value of the right-hand side, which is the behaviour in 2.1.0-p0, 2.0.0-p353 and 1.9.3-p484.

Example code:

class Animal                                                                                                                  
  def []=(key, new_value)                                                                                                      
    "walrus"                                                                                                                 
  end                                                                                                                          
end                                                                                                                            
animal = Animal.new                                                                                                               
puts animal['current'] = "unicorn" 

In trunk, this returns 'walrus'. In other releases (tested in the ones mentioned above), this returns 'unicorn'.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0