Hi -- On Thu, 22 Sep 2005, Michael Ehehalt wrote: > Hi, > > the code: > > idea = ["a","b","c","d"] > idea.push( idea.shift ) > > lets the array rotate to the left and returns ["b", "c", "d", "a"] > > the code: > > idea = ["a","b","c","d"] > idea.unshift( idea.pop ) > p idea > > lets rotate to the right and returns: ["d", "a", "b", "c"] > > Is this what you mean? I think Travis wanted to do that without changing the original array -- something like: idea = %w{a b c d} new_idea = [idea[-1], *idea[0..-2]] (Obviously not a full implementation, but just illustrating the non-changingness.) David > > Michael > > > > > > > > > "travis laduke" <wrong / socal.rr.com> schrieb im Newsbeitrag > news:7501E02B-A490-423F-B99B-8EF43D1CA11F / socal.rr.com... >> I've been forced to work on some php lately and found myself thinking: >> "man, this sucks. i wish it was more like supercollider" >> then i remembered supercollider is ruby-influenced so i started reading >> about ruby. >> >> Here's my question: is there a common way to rotate a string or an array? >> >> I thought i could do some combination of .pop and .unshift or something, >> but i ran into this problem: >> >> idea = ["a","b","c","d"] >> x = idea.pop >> puts idea >> >> why is idea changed? how do i make it stay the same? >> why is it different than: >> >> x = idea.reverse >> >> where idea is left alone and only x is the reversed array? >> >> >> >> -travis >> >> > > > -- David A. Black dblack / wobblini.net