class Liquid::ForloopDrop

@liquid_public_docs @liquid_type object @liquid_name forloop @liquid_summary

Information about a parent [`for` loop](/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]

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 74
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 42
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 50
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 82
def last
  @index == @length - 1
end
name() click to toggle source
# File lib/liquid/forloop_drop.rb, line 33
def name
  Usage.increment('forloop_drop_name')
  @name
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 58
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 66
def rindex0
  @length - @index - 1
end

Protected Instance Methods

increment!() click to toggle source
# File lib/liquid/forloop_drop.rb, line 88
def increment!
  @index += 1
end