From: Boby Selamet Hartono Date: 2009-05-14T16:34:24+09:00 Subject: Re: find previous & next in array --00163630f2df47d5160469da5bc4 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 2009/5/14 Joshua Collins > Boby had it almost right! > > instead of: > > a[a.index(:c)+1] > > it is: > > a[a.index('c')+1] > > :-) > > On Wed, May 13, 2009 at 11:48 PM, Boby Selamet Hartono > wrote: > > > 2009/5/14 John Griffiths > > > > > hi, anyone know how to do this? > > > > > > basically i've got an array of items > > > > > > a = ['a','b','c','d'] > > > > > > now given i can find the position of say 'c' using .index('c'), how do > i > > > get the positions of the ones previous & next to it. > > > > > > a recursive routine would probably do it, but looking for something > more > > > flash > > > > > > any ideas? > > > -- > > > Posted via http://www.ruby-forum.com/. > > > > > > > > a[a.index(:c)-1] or a[a.index(:c)+1]? > > > > -- > > Tidak ada yang lebih baik dari kembali ke asal > > Nothing can be better than back to the roots > > > It was a copy from my irb. I'm use symbols as objects in my array. I've never use index method but since I figure out that method returns an Integer I think it would be something like that (thanks to irb). I'm a newbie and just joining this ML yesterday :-). -- Tidak ada yang lebih baik dari kembali ke asal Nothing can be better than back to the roots --00163630f2df47d5160469da5bc4--