This is the snippet of code i'm using now:
def countOccurences(a, b)
#counts the number of occurences of a in b
count=0
cur=0
while cur < b.length do
temp=b.index(a, cur)
if temp == nil
break
end
count=count+1
cur=temp+a.length
end
return count
end
Is there any Ruby function that does this? Any functional equivalent? Or anything better?