class REXML::Element

def each_with_something( test, max=0, name=nil )

A private helper method
def each_with_something( test, max=0, name=nil )
  num = 0
  @elements.each( name ){ |child|
    yield child if test.call(child) and num += 1
    return if max>0 and num == max
  }
end