bug: add_match with index
Kevin Ballard
kevin at sb.org
Mon Sep 26 01:32:22 EDT 2005
Why not just use Array#insert instead of Array#[]=?
On Sep 25, 2005, at 12:41 PM, Grant Hollingworth wrote:
> I don't think it's used anywhere, but UserScript.add_match (and so
> include_match and exclude_match) can add a match at a specific
> index in
> the match list.
>
> def add_match r, m, i = nil
> r.strip! if r.respond_to? :strip!
> if i; self.matches[i+1, 0] = [r, m]
> else; self.matches << [r, m] end
> end
>
> However:
> irb(main):001:0> a = [[1,1],[2,2],[3,3]]
> => [[1, 1], [2, 2], [3, 3]]
> irb(main):002:0> a << [4,4]
> => [[1, 1], [2, 2], [3, 3], [4, 4]]
> irb(main):003:0> a[1,0] = [5,5]
> => [5, 5]
> irb(main):004:0> a
> => [[1, 1], 5, 5, [2, 2], [3, 3], [4, 4]]
>
> So it should be
> if i; self.matches[i+1, 0] = [[r, m]]
>
> I'm not sure about the '+1', either.
--
Kevin Ballard
kevin at sb.org
http://www.tildesoft.com
http://kevin.sb.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2378 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/mousehole-scripters/attachments/20050926/8e9a81d9/smime-0001.bin
More information about the Mousehole-scripters
mailing list