Prev: Error on iterating through a set of nested tables in a form
Next: Making a VALUE visible to multiple source files
From: Harry Kakueki on 27 Feb 2010 18:51 On Fri, Feb 26, 2010 at 7:13 AM, David Springer <dnspringer(a)gmail.com> wrote: > after some inspiration from Luc I was able to come up with this: > > textlist = ["Apple", "Orange", "Lemon", "Grape", "Orange", > > (0..textlist.length-1).select {|i| textlist[i] == "Orange"}[1] > Same thing only different :) p textlist.fill{|x| x if textlist[x] == "Orange"}.compact[1] Harry
From: Alex Baranosky on 28 Feb 2010 01:55
Here's my solution in 1.9: class Array def indices_of(value) indices = self.each_with_index.select { |v, i| v == value }.collect{|v, i| i } indices.empty? ? nil : indices end end -- Posted via http://www.ruby-forum.com/. |