class Liquid::ForloopDrop
@liquid_public_docs @liquid_type object @liquid_name forloop @liquid_summary
Information about a parent [`for` loop](/docs/api/liquid/tags/for).
Attributes
length[R]
@liquid_public_docs @liquid_name length @liquid_summary
The total number of iterations in the loop.
@liquid_return [number]
name[R]
parentloop[R]
@liquid_public_docs @liquid_name parentloop @liquid_summary
The parent `forloop` object.
@liquid_description
If the current `for` loop isn't nested inside another `for` loop, then `nil` is returned.
@liquid_return [forloop]
Public Class Methods
new(name, length, parentloop)
click to toggle source
# File lib/liquid/forloop_drop.rb, line 10 def initialize(name, length, parentloop) @name = name @length = length @parentloop = parentloop @index = 0 end
Public Instance Methods
first()
click to toggle source
@liquid_public_docs @liquid_summary
Returns `true` if the current iteration is the first. Returns `false` if not.
@liquid_return [boolean]
# File lib/liquid/forloop_drop.rb, line 71 def first @index == 0 end
index()
click to toggle source
@liquid_public_docs @liquid_summary
The 1-based index of the current iteration.
@liquid_return [number]
# File lib/liquid/forloop_drop.rb, line 39 def index @index + 1 end
index0()
click to toggle source
@liquid_public_docs @liquid_summary
The 0-based index of the current iteration.
@liquid_return [number]
# File lib/liquid/forloop_drop.rb, line 47 def index0 @index end
last()
click to toggle source
@liquid_public_docs @liquid_summary
Returns `true` if the current iteration is the last. Returns `false` if not.
@liquid_return [boolean]
# File lib/liquid/forloop_drop.rb, line 79 def last @index == @length - 1 end
rindex()
click to toggle source
@liquid_public_docs @liquid_summary
The 1-based index of the current iteration, in reverse order.
@liquid_return [number]
# File lib/liquid/forloop_drop.rb, line 55 def rindex @length - @index end
rindex0()
click to toggle source
@liquid_public_docs @liquid_summary
The 0-based index of the current iteration, in reverse order.
@liquid_return [number]
# File lib/liquid/forloop_drop.rb, line 63 def rindex0 @length - @index - 1 end
Protected Instance Methods
increment!()
click to toggle source
# File lib/liquid/forloop_drop.rb, line 85 def increment! @index += 1 end