bug: add_match with index

Grant Hollingworth grant at antiflux.org
Sun Sep 25 12:41:04 EDT 2005


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.


More information about the Mousehole-scripters mailing list