From: "David A. Black" Date: 2005-10-04T00:38:53+09:00 Subject: Re: How does this work? def[](own_arg_1, own_arg_2) Hi -- On Tue, 4 Oct 2005, Krekna Mektek wrote: > Hi, > > While reading some code, which tells that one can define a new > indexing operator, some of my neurons triggered a question. When > evaluating this code: > > class Song > def[](from_time, to_time) > result = Song.new(self.title + " [extract]", > self.artist > to_time - from_time) > result.set_start_time(from_time) > result > end > end > > song[0,15].play > > I was thinking: when one usually defines a method, the arguments are > placed after the method name, which is '[]' here, or so I thought. > That would be song[](0,15).play Actually the full method-call version would be: song.[](0,15).play # note the first dot > How come it works 'just' by putting the argument between the brackets? Because Matz is nice and gave us some nice syntactic sugar :-) David -- David A. Black dblack@wobblini.net