From 3d359cecd815f6d6cd9eeb55e14f38de75ab03ee Mon Sep 17 00:00:00 2001 From: seki Date: Tue, 6 Apr 2004 15:26:25 +0000 Subject: fix hash tuple bug git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rinda/rinda.rb | 18 +++++++++++++++--- lib/rinda/tuplespace.rb | 4 ++++ 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'lib/rinda') diff --git a/lib/rinda/rinda.rb b/lib/rinda/rinda.rb index c06096cc48..a977d5c525 100644 --- a/lib/rinda/rinda.rb +++ b/lib/rinda/rinda.rb @@ -18,6 +18,8 @@ require 'thread' # This is part of +drb+ (dRuby). # module Rinda + class RindaError < RuntimeError; end + class InvalidHashTupleKey < RindaError; end class RequestCanceledError < ThreadError; end class RequestExpiredError < ThreadError; end @@ -46,6 +48,10 @@ module Rinda @tuple[k] end + def fetch(k) + @tuple.fetch(k) + end + # Iterate through the tuple, yielding the index or key, and the # value, thus ensuring arrays are iterated similarly to hashes. def each # FIXME @@ -74,7 +80,8 @@ module Rinda @tuple_size = hash[:size] @tuple = Hash.new hash.each do |k, v| - next unless String === k + next if k == :size + raise InvalidHashTupleKey unless String === k @tuple[k] = v end end @@ -89,11 +96,16 @@ module Rinda # matching any value in the corresponding position in the tuple. def match(tuple) return false unless tuple.respond_to?(:size) - return false unless tuple.respond_to?(:[]) + return false unless tuple.respond_to?(:fetch) return false if @tuple_size && (@tuple_size != tuple.size) each do |k, v| + begin + it = tuple.fetch(k) + rescue + return false + end next if v.nil? - return false unless (v === tuple[k] rescue false) + return false unless (v === it) end return true end diff --git a/lib/rinda/tuplespace.rb b/lib/rinda/tuplespace.rb index d30a5047a8..2353446857 100644 --- a/lib/rinda/tuplespace.rb +++ b/lib/rinda/tuplespace.rb @@ -89,6 +89,10 @@ module Rinda @ary[key] end + def fetch(key) + @ary.fetch(key) + end + # The size of the tuple. def size @ary.size -- cgit v1.2.3