diff options
author | seki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-04-06 15:26:25 +0000 |
---|---|---|
committer | seki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-04-06 15:26:25 +0000 |
commit | 3d359cecd815f6d6cd9eeb55e14f38de75ab03ee (patch) | |
tree | d184a84cc7c33fcdbc8c1c84ac868570da068605 /lib/rinda | |
parent | 383964bc30a9e0b9f8f8a17dbf0ecd9450bfb90e (diff) | |
download | ruby-3d359cecd815f6d6cd9eeb55e14f38de75ab03ee.tar.gz |
fix hash tuple bug
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rinda')
-rw-r--r-- | lib/rinda/rinda.rb | 18 | ||||
-rw-r--r-- | lib/rinda/tuplespace.rb | 4 |
2 files changed, 19 insertions, 3 deletions
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 |