From: Piers Cawley Date: 2001-09-07T23:42:55+09:00 Subject: [ruby-talk:20982] Re: calling original method in overrided method? Piers Cawley writes: > Henry House writes: > > > I don't like the default behavior of String#to_i and String#to_f to return > > zero for any string that contains no recognizable numbers. I had thought to > > write overriding methods like so: > > > > Class String > > def to_i > > fail "#{self} is not a valid integer" unless self =~ /^\d*$/ > > Note that this will only find you positive integers. Maybe you mean > > self =~ /^[-+]?\d*$/ > > > # call original to_i > > end > > end > > > > ...but I don't how (if it is possible?) to call the original to_i. > > Am I stuck with using a new method name or a custom string class? > > Frankly I'd hope that 'super' would do the job, but it seems from the > rest of the thread that it doesn't... And then I realised how stupid I was being... We return you now to your scheduled wisdom and insight, untroubled by the stupidity inherent in my post above. -- Piers Cawley www.iterative-software.com