From: Rick DeNatale Date: 2006-08-11T09:29:18+09:00 Subject: Re: Overriding String#[] On 8/10/06, Lukasz Muziol wrote: > The generic question would be "does anyone know a decent and complete > reference to Ruby's syntax?" > > What interests me is the syntax required to define methods like [], []=, > getting their parameters in between the braces. It's fairly > inconvienient that String#[] returns a character code, rather than a > string of one character. Hope it'll get changed soon (to get in line > with POLS perhaps :)), accomodating my laziness for now I hope to > override it. How do I define a function named like this? Well the syntax is: class String def [](arg) end end But, this one seems like a pretty dangerous mod to me, with the potential to break lots of things. But, keep in mind that while: irb(main):001:0> "abc"[1] => 98 you can get the result you want without changing Strings [] method. irb(main):002:0> "abc"[1..1] => "b" -- Rick DeNatale http://talklikeaduck.denhaven2.com/