From: Joshua Collins Date: 2009-05-15T02:34:50+09:00 Subject: Re: find previous & next in array --001e680f0ff498f1cb0469e2be6c Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Bobby, I am new too, so I might be missing something as well. I tried your method first, and when I tried to do the symbol in irb it gave an error. Maybe you have settings I do not? On Thu, May 14, 2009 at 11:38 AM, John Griffiths wrote: > > The safest is probably > > > > i = a.index('c') > > > > if i > > predecessor = i > 0 ? a[i -1] : nil > > successor = a[i + 1] # safe! > > end > > > > Or as a variant > > > > i = a.index('c') and begin > > predecessor = i > 0 ? a[i -1] : nil > > successor = a[i + 1] # safe! > > end > > > > Kind regards > > > > robert > > thanks Robert, i was trying to build up a little function to find the > prev/next elements in an array, thanks to your help it's sorted; > couldn't find a solution online. appreciate it all. > > > John. > -- > Posted via http://www.ruby-forum.com/. > > --001e680f0ff498f1cb0469e2be6c--