summaryrefslogtreecommitdiffstats
path: root/lib/rinda/rinda.rb
diff options
context:
space:
mode:
authorseki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-04-06 15:26:25 +0000
committerseki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-04-06 15:26:25 +0000
commit86a34bd0f3b11183e1f8d0f7b6b2589a7a7d9710 (patch)
treed184a84cc7c33fcdbc8c1c84ac868570da068605 /lib/rinda/rinda.rb
parent384413139860fab487582faa3f32ecea87edf0e8 (diff)
downloadruby-86a34bd0f3b11183e1f8d0f7b6b2589a7a7d9710.tar.gz
ruby-86a34bd0f3b11183e1f8d0f7b6b2589a7a7d9710.tar.xz
ruby-86a34bd0f3b11183e1f8d0f7b6b2589a7a7d9710.zip
fix hash tuple bug
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@6111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rinda/rinda.rb')
-rw-r--r--lib/rinda/rinda.rb18
1 files changed, 15 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