From: Gary Wright Date: 2008-02-14T05:27:57+09:00 Subject: Re: ruby wish-list On Feb 13, 2008, at 2:56 PM, Roger Pack wrote: > or maybe not even use brackets at all--they confuse with their > similarity to arrays. > Thoughts? I tend to define [] and []= whenever possible if the object behaves like an indexed collection of objects. I think this helps with duck- typing. If every collection had a different manner of indexing items it would defeat any duck-typing. Less common, but also useful is to provide fetch/store in addition to [] and []=. The fetch API is nice when you want to substitute a different default value: fetch(index) # get item or raise exception fetch(index, miss) # get item or return miss fetch(index) { } # get item or compute miss Gary Wright