Hi –
On Fri, 28 Aug 2009, Harry K. 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 (The Well-Grounded Rubyist)
September Ruby training in NJ has been POSTPONED. Details to follow.