Skip to content

Commit

Permalink
support triple-dot range notation for list objects
Browse files Browse the repository at this point in the history
  • Loading branch information
neilmock committed Sep 12, 2011
1 parent af91e33 commit 8201554
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/redis/list.rb
Expand Up @@ -55,7 +55,8 @@ def values
# a range of values using Redis: LRANGE.
def [](index, length=nil)
if index.is_a? Range
range(index.first, index.last)
last = index.exclude_end? ? (index.last - 1) : index.last
range(index.first, last)
elsif length
case length <=> 0
when 1 then range(index, index + length - 1)
Expand Down
1 change: 1 addition & 0 deletions spec/redis_objects_instance_spec.rb
Expand Up @@ -147,6 +147,7 @@
# Test against similar Ruby functionality
a = @list.values
@list[0..2].should == a[0..2]
@list[0...2].should == a[0...2]
@list.slice(0..2).should == a.slice(0..2)
@list[0, 2].should == a[0, 2]
@list.range(0, 2).should == a[0..2] # range for Redis works like .. in Ruby
Expand Down

0 comments on commit 8201554

Please sign in to comment.