Ma Fe wrote:
> well I dont know where in array i have .txt files but its sure that
> there is just one and i want to put it at first place of array...
> a.select {|i| i =~ /\..txt$/}
That doesn't work.
> b = a.partition {|i| i =~ /\.txt$/}
Neither does that.
This is faster than all the solutions posted so far:
a = ['one.jpg', 'two.kzv', 'a.txt', 'a.az']
new_a = [1]
for elmt in a
if elmt[-3] == ?t
new_a[0] = elmt
else
new_a << elmt
end
end
--output:--
["a.txt", "one.jpg", "two.kzv", "a.az"]
--
Posted via
http://www.ruby-forum.com/.