From: Rail Shafigulin Date: 2011-01-07T03:03:53+09:00 Subject: ruby method definition i'm somewhat new to ruby, and as it seems this language is redefining programming for me. there is a piece of code i'm trying to understand: class SongList def [](key) if key.kind_of?(Integer) @songs[key] else # ... end end end list = SongList.new list.append(Song.new('title1', 'artist1', 1)). list.append(Song.new('title2', 'artist2', 2)). list.append(Song.new('title3', 'artist3', 3)). list.append(Song.new('title4', 'artist4', 4)) list[0] » Song: title1--artist1 (1) list[2] » Song: title3--artist3 (3) list[9] » nil i can't understand why i'm allowed to call a [] method in this manner, i.e. list[index], shouldn't i call it like list.[](index) any help and explanation is appreciated -- Posted via http://www.ruby-forum.com/.