タスクの制御には向くけど、データを蓄える場所としては使いにくい気がする > Rinda。
require 'rinda/tuplespace' module Rinda class TupleSpace def take?(pattern) take(pattern, 0) rescue nil end end end ts = Rinda::TupleSpace.new while line = gets line.chomp.split(/\W+/).each do |word| next if word.empty? ts.write([word.intern, ARGF.filename, ARGF.file.lineno]) end end while tuple = ts.take?([Symbol, String, Integer]) ary = [] word, filename, lineno = tuple ary.push([filename, lineno]) while tuple = ts.take?([word, String, Integer]) temp, filename, lineno = tuple ary.push([filename, lineno]) end ts.write([word, ary]) end ts.read_all([Symbol, Array]).each do |x| p x end
ね。かっこわるいでしょう?
それはそれとして、タプルの検索をさぼるための特別なキー(Rinda::KeyとRinda::Prefix)を用意したらどうなるか実験中。