-
-
Save pangloss/1095339 to your computer and use it in GitHub Desktop.
Pacer loop test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/setup' | |
require 'pacer' | |
graph = Pacer.tg | |
c1 = graph.create_vertex(name: 'Concept 1') | |
c2 = graph.create_vertex(name: 'Concept 2') | |
c2a = graph.create_vertex(name: 'Concept 2a') | |
graph.create_edge(nil, c2, c2a, :same_as) | |
c2b = graph.create_vertex(name: 'Concept 2b') | |
graph.create_edge(nil, c2a, c2b, :same_as) | |
c2c = graph.create_vertex(name: 'Concept 2c') | |
graph.create_edge(nil, c2b, c2c, :same_as) | |
c3 = graph.create_vertex(name: 'Concept 3') | |
# Works in irb but not "ruby" | |
c2.out_e(:same_as).in_v.loop { |v| | |
v.out_e(:same_as).in_v | |
}.while do |node,depth| | |
puts (' ' * depth) + node[:name] | |
:loop | |
end | |
# Doesn't work in irb or "ruby" | |
[c1, c2, c3].each do |cr| | |
puts cr[:name] | |
unless cr.out_e(:same_as).empty? | |
cr.out_e(:same_as).in_v.loop { |v| | |
v.out_e(:same_as).in_v | |
}.while do |node,depth| | |
puts (' ' * depth) + node[:name] | |
:loop | |
end.to_a | |
end | |
end | |
# Another way: | |
[c1, c2, c3].each do |cr| | |
# the #v method turns the vertex into a route so that the loop method is available on it. | |
cr.v.loop { |v| | |
v.out_e(:same_as).in_v | |
}.while do |node,depth| | |
puts (' ' * depth) + node[:name] | |
:loop | |
end.to_a | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment