On Nov 24, 2005, at 3:27 AM, jchris / gmail.com wrote: > But the last one is nasty. When I try to define this: > > def items[]= (index, newitem) > ...doesn't matter what's here... > end You can't do this in Ruby because unlike the assignment method syntax, you can't prefix []= with an identifier: def whatever=(arg); end # OK def whatever[]=(index, arg); end # syntax error The main problem is that it would create an ambiguous parsing situation for x[i] = v 1) self.x.[]=(i, v) 2) self.x[]=(i, v) and similarly for the lookup x[i]. It isn't simple because the parser can't know ahead of time what 'x' is referencing and so can't know which interpretation is the sensible one. It would be a useful construct because it would allow a class to manage the interface to container objects without having to create a proxy for the containers. Right now you have to give up the []/[]= syntax and use something like set_item(i, v) get_item(i) or you have to construct a proxy class for the container or you have to expose the entire container to the client. I suggested a couple weeks ago an alternate syntax such as: def whatever@[](index); end def whatever@[]=(index, var); end With this syntax you can write: item = obj.item@[5] obj.item@[5] = new_item and the parser would know that item@[] and item@[]= were methods based on the syntax. It might be possible to to discard the []'s but I wasn't sure if that would create some ambiguity with instance variables. I just didn't explore the idea that deeply. Gary Wright