Wayne E. Seguin wrote:
> On 10/11/07, Giles Bowkett <gilesb / gmail.com> wrote:
>> I think the OP was looking for a method on String itself, but the
>> whole point of Ruby is that if the language doesn't have the features
>> you want, you just add the features to the language.
>>
>> class String
>>   def delete_n_from_p(n, p)
>>     n.times do
>>       self[p] = ''
>>     end
>>     self
>>   end
>> end
>>
>>>> "muppet".delete_n_from_p(2,3)
>> => "mupt"
>>
>> That makes it easy to reuse the functionality.
>>
>> --
>> Giles Bowkett
>>
> 
> 
> This little problem is quite enjoyable:
> 
> class String
>   def delete_indices(*indices)
>     indices.each do |index|
>       self[index] = ''
>     end
>     self
>   end
> end
> 
>>> a = "Testing String"
> => "Testing String"
>>> a.delete_indices(0,3,6,8)
> => "estng trng"

What's your point? Your code probably won't do what it seems to intend
to, because the characters shift to the left during the process.
However, Giles' code seems to be OK, because it deletes from the same
position, n times, which'll do what it's supposed to.

mortee