Fredrik Jagenheim <fredde / pobox.com> wrote:
 
> Anyway, then I started to think about using a superclass for these
> classes and use Ruby introspection to find all the subclasses and call
> match from there. That's when I realized there must be simpler
> solution I just can't see...

Here's one way (untested)

class SetMatcher
  def initialize
    @tests = []
  end

  def add(&test)
    @tests << test
  end

  def match?(set)
    @tests.all? {|test| test.call(set)}
  end
end

m = SetMatcher.new
m.add {|set| 
   #complex test
}

m.add {|set|
  #complex test
}

s = DataSet.new(datasource)
if m.match?(s)
  ...
end

#---------------------------------------------------------

You could also rewrite it slightly to be a module mixed into your set
class, in which case match? wouldn't need a parameter, as wouldn't the
matching procs.

martin