Convert forloop hash to drop

This commit is contained in:
Florian Weingarten
2016-01-06 21:30:32 +00:00
parent 1662ba6679
commit e113c891ec
3 changed files with 45 additions and 13 deletions
+42
View File
@@ -0,0 +1,42 @@
module Liquid
class ForloopDrop < Drop
def initialize(name, length, parentloop)
@name = name
@length = length
@parentloop = parentloop
@index = 0
end
attr_reader :name, :length, :parentloop
def index
@index + 1
end
def index0
@index
end
def rindex
@length - @index
end
def rindex0
@length - @index - 1
end
def first
@index == 0
end
def last
@index == @length - 1
end
protected
def increment!
@index += 1
end
end
end