require 'rubygems' require 'neo4j-core' def connect(d) d.each{|i| Neo4j::Relationship.new(:flies_to, i[:from], i[:to])} end puts "Using #{Neo4j::Core::VERSION}" tx = Neo4j::Transaction.new @a, @b, @c, @z = (1..4).map{Neo4j::Node.new} connect([ {:from=>@a, :to=>@b}, {:from=>@a, :to=>@c}, {:from=>@b, :to=>@c}, {:from=>@b, :to=>@z}, {:from=>@c, :to=>@b}, {:from=>@c, :to=>@z}]) tx.success tx.finish traversal = @a.outgoing(:flies_to).depth(:all).eval_paths { |path| :include_and_continue } # This prints out #Path (1)--[flies_to,0]-->(2) #Path (1)--[flies_to,1]-->(3) #Path (1)--[flies_to,0]-->(2)--[flies_to,3]-->(4) traversal.paths.each do |path| puts "Path #{path.to_s}" end