かなり短い。
def parse_sgraph file sgraph ||= [] nodes, arcs = 0, 0 File.open(file).each do |line| case line when /^a +(d+) +(d+) +(d+)/ sgraph[$1.to_i] ||= [] sgraph[$1.to_i] << [$2.to_i, $3.to_i] when /^p +sp +(d+) +(d+)/ nodes, arcs = $1.to_i, $2.to_i when /^[c,n]/ # comment. skip. else raise "Parse Error!!" end end return sgraph end