lib/cassandra/ordered_hash.rb in cassilds-0.9.2 vs lib/cassandra/ordered_hash.rb in cassilds-0.12.1
- old
+ new
@@ -1,11 +1,7 @@
# OrderedHash is namespaced to prevent conflicts with other implementations
class Cassandra
- # Hash is ordered in Ruby 1.9!
- if RUBY_VERSION >= '1.9'
- OrderedHashInt = ::Hash
- else
class OrderedHashInt < Hash #:nodoc:
def initialize(*args, &block)
super
@keys = []
end
@@ -124,22 +120,25 @@
def replace(other)
super
@keys = other.keys
self
end
+
+ def reverse
+ OrderedHashInt[self.to_a.reverse]
+ end
private
def sync_keys!
@keys.delete_if {|k| !has_key?(k)}
end
end
- end
class OrderedHash < OrderedHashInt #:nodoc:
def initialize(*args, &block)
- @timestamps = Hash.new
+ @timestamps = OrderedHashInt.new
super
end
def initialize_copy(other)
@timestamps = other.timestamps
@@ -154,17 +153,17 @@
def delete(key)
@timestamps.delete(key)
super
end
- def delete_if
- @timestamps.delete_if
+ def delete_if(&block)
+ @timestamps.delete_if(&block)
super
end
- def reject!
- @timestamps.reject!
+ def reject!(&block)
+ @timestamps.reject!(&block)
super
end
def timestamps
@timestamps.dup
@@ -187,14 +186,7 @@
end
def inspect
"#<OrderedHash #{super}--TimeStamps: #{@timestamps.inspect}>"
end
-
- private
-
- def sync_keys!
- @timestamps.delete_if {|k,v| !has_key?(k)}
- super
- end
end
-end
\ No newline at end of file
+end