il Mon, 26 Jan 2004 19:50:26 GMT, Gavin Kistner <gavin / refinery.com> ha scritto:: >#Works >class Foo1 > def [](x) > #... > end >end > >#Syntax Error >class Foo2 > def bar[](x) > #... > end >end > > >Is there no way to define a method that has a name and [] in it, to be >able to do something like: > >myObj = Foo.new >puts myObj.bar[12] > > >...without having to create a new class for bar and define the [] method >in that class? >> class C >> def initialize >> @bar=method :met >> end >> def met(x) >> x**2 >> end >> private :met >> attr_reader :bar >> end => nil >> C.new.bar[12] => 144 alla callable objects (proc, method, continuations have a [] method. But I'm not sure this is what you would see :)