From: "Brian Schröder" Date: 2004-10-06T02:58:50+09:00 Subject: Re: A ruby course Henrik Horneber wrote: > Brian Schr�der wrote: > >> Hello Group, >> >> I need more help. >> >> Gavin Sinclair wrote: >> >>> >>> p51. Good exercise. How about another? >>> >> >> Anybody has an idea for an exercise on extending existing classes. So >> far the only thing I have come up with is: >> >> \exercise{Fibonacci II}{ >> Extend \codetype{Integer} with a function fib that calculates the >> corresponding fibonacci number.} >> >> And my creativity is at an all time low. >> > > Hi! > > what about > - extending REXML::Element with a method that strips all unnecessary > whitespaces and all children > - extending String so you can tell it to remove cpp comments /* remove > me */ > > Of course both tasks could be accomplished without extending those > classes. I have no idea in which cases you should write helper methods > and when you should extend existing classes... does anybody have some > 'heuristics' or best practices? > > regards, > Henrik > Hello Henrik, Sadly I don't want to introduce REXML (even though its a great library). But this would cost me too much time. Extending string with something like remove_cpp_comments seems awkward to me. In any usecase for this I'd rather have a class CppCode that I can ask to remove_comments. (Or even better, to give me the source without comments.) So my personal heuristic tells me not to extend in this case. thanks for your comment, Brian -- Brian Schr�der http://ruby.brian-schroeder.de/