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 | c8d5f06b1c2a7627b432a58fbf08493f200815c6 (patch) | |
| tree | 4dd32a4eabd9f71c5de8fc8450061fe34fee6d14 /lib | |
| parent | 4fbac4522ee279def63ceab3f8bf3710473fcee1 (diff) | |
| download | ruby-c8d5f06b1c2a7627b432a58fbf08493f200815c6.tar.gz ruby-c8d5f06b1c2a7627b432a58fbf08493f200815c6.tar.xz ruby-c8d5f06b1c2a7627b432a58fbf08493f200815c6.zip | |
fix hash tuple bug
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@6111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -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 c06096cc4..a977d5c52 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 d30a5047a..235344685 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 |
