From: Rob Biedenharn Date: 2008-02-05T22:24:38+09:00 Subject: Re: got any good string exercises? On Feb 5, 2008, at 8:05 AM, Adam Akhtar wrote: > Looking for fairly simple string exercises that will familiarise > myself > with all those string methods in the back of pickaxe. Dont want major > exercises like those in the ruby quiz as they demand knowledge in a > lot > of other areas. > > Heres one example of the sort im looking for > > Rotate the words in a string around a fixed point given by a letter. > Eg. > string = "Ruby is a great language" > puts Rotate(string, "a") > > output: "a great language ruby is" > > ok that one is probably at upper end of the scale when it comes to > difficulty but its quite focused. > > Anyone got any other string practice exercises that are short, > relatively simple and use some of the methods?? Well, you could always tackle the ones that pop up continually on this list. Also, you will almost certainly have to know about more than just String to do most things. First of all, the method would be called "rotate", not "Rotate". Initial capitals are an indication of a constant in Ruby. You'd either have: def rotate(string, to_word) ... end to define a standalone method (which you'd likely do only in irb), or: class String def rotate(to_word) # do something with self, probably returning a new String ... end end to let you say something like: "Ruby is a great language".rotate("a") In any case, just try to solve something and if you want help, post your attempt to the list and be specific about the amount of help that you want (or you'll get solutions rather than hints). -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com