From: "David A. Black" Date: 2009-08-29T08:02:05+09:00 Subject: Re: I need a string#all_indices method--is there such a thing? Hi -- On Fri, 28 Aug 2009, Harry Kakueki wrote: > class String > def all_indices(reg) > idx = [] > (0...self.length).each{|x| idx << x if self[x..-1] =~ /\A#{reg}/} > idx > end > end Might as well let #select do the choosing: def all_indices(re) (0...size).select {|i| self[i..-1][/\A#{re}/] } end And maybe better to create the regex only one: def all_indices(re) re = /\A#{re}/ (0...size).select {|i| self[i..-1][re] } end David -- David A. Black / Ruby Power and Light, LLC / http://www.rubypal.com Ruby/Rails training, mentoring, consulting, code-review Latest book: The Well-Grounded Rubyist (http://www.manning.com/black2) September Ruby training in NJ has been POSTPONED. Details to follow.