lib/redis/list.rb in redis-objects-1.4.3 vs lib/redis/list.rb in redis-objects-1.5.0
- old
+ new
@@ -1,20 +1,13 @@
-require File.dirname(__FILE__) + '/base_object'
+require File.dirname(__FILE__) + '/enumerable_object'
class Redis
#
# Class representing a Redis list. Instances of Redis::List are designed to
# behave as much like Ruby arrays as possible.
#
- class List < BaseObject
- require 'enumerator'
- include Enumerable
- require 'redis/helpers/core_commands'
- include Redis::Helpers::CoreCommands
-
- attr_reader :key, :options
-
+ class List < EnumerableObject
# Works like push. Can chain together: list << 'a' << 'b'
def <<(value)
push(value) # marshal in push()
self # for << 'a' << 'b'
end
@@ -121,16 +114,10 @@
# Redis: LREM
def delete(name, count=0)
redis.lrem(key, count, marshal(name)) # weird api
end
- # Iterate through each member of the set. Redis::Objects mixes in Enumerable,
- # so you can also use familiar methods like +collect+, +detect+, and so forth.
- def each(&block)
- values.each(&block)
- end
-
# Return a range of values from +start_index+ to +end_index+. Can also use
# the familiar list[start,end] Ruby syntax. Redis: LRANGE
def range(start_index, end_index)
redis.lrange(key, start_index, end_index).map{|v| unmarshal(v) }
end
@@ -166,12 +153,8 @@
values == x
end
def to_s
values.join(', ')
- end
-
- def as_json(*)
- to_hash
end
end
end