def <=>(node)
ancestors1 = [self]
ancestors2 = [node]
p = self
while p = p.parentNode
ancestors1.unshift(p)
end
p = node
while p = p.parentNode
ancestors2.unshift(p)
end
raise "different document" unless ancestors1[0].equal?(ancestors2[0])
ret = 0
i = 0
for i in 1...ancestors1.size
next if ancestors1[i].equal?(ancestors2[i])
return 1 if ancestors2[i].nil?
children = ancestors1[i - 1].childNodes.to_a
return children.index(ancestors1[i]) - children.index(ancestors2[i])
end
return -1 if ancestors2.size > i + 1
0
end