Hi --

On Tue, 8 Jun 2004, Richard Kilmer wrote:

> Moreover, if you could do that syntactically (ie. Change Ruby to support
> this kind of thing) like the following (love it or hate it) syntax:
> 
> class Foo
> 
>   def {Hash}[](key)
>     @mymap[key]
>   end
> 
>   def {Hash}[]=(key, value)
>     @mymap[key] = value
>   end
> 
> end
> 
> f = Foo.new
> f{Hash}['name']="rich"
> 
> ...but you don't always need the {...}
> 
> p f['name'] => 'rich'
> 
> ...and if you do something that's naughty...
> 
> p f{Array}[1] => raise Exception...

It would have to be something slightly different from that, though,
because of:

  irb(main):008:0> def f; [1,2,3]; end
  => nil
  irb(main):009:0> f{Array}[1]
  => 2


David

-- 
David A. Black
dblack / wobblini.net