K
Krekna Mektek
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 =3D 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
How come it works 'just' by putting the argument between the brackets?
Krekna Mektek
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 =3D 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
How come it works 'just' by putting the argument between the brackets?
Krekna Mektek