From: ts Date: 2001-08-16T01:02:14+09:00 Subject: [ruby-talk:19795] Re: 2 iterator questions >>>>> "M" == Mark Slagell writes: M> 2. The conversion of a block to a proc inside an iterator(sec. 5.3) is M> interesting... I'm curious what use it might have though. Any thoughts? Well, there are many examples. In bdb I use it to implement secondary indexes. The block is called each time a (key, value) is inserted in the db file to create the second index. pigeon% cat b.rb #!/usr/bin/ruby $LOAD_PATH.unshift "src" require 'bdb' cat = Struct.new("Cat", :name, :age, :life) bdb = BDB::Btree.open "tmp/aa", nil, BDB::CREATE, "marshal" => true aux = BDB::Btree.open "tmp/bb", nil, BDB::CREATE, "set_flags" => BDB::DUP | BDB::DUPSORT, "marshal" => true bdb.associate(aux) { |aux, key, value| value.life } bdb["aa"] = cat.new "cat1", 12, 7 bdb["ab"] = cat.new "cat2", 12, 6 bdb["ac"] = cat.new "cat3", 12, 5 bdb["ad"] = cat.new "cat4", 12, 7 aux.each do |k, v| p "key :#{k} -- value #{v.inspect}" end pigeon% pigeon% b.rb "key :5 -- value #" "key :6 -- value #" "key :7 -- value #" "key :7 -- value #" pigeon% Guy Decoux