From: Harry Kakueki on
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
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/.