class Liquid::Block::For

Overview

Inside of a for-loop block, you can access some special variables: Variable Description loop.index The current iteration of the loop. (1 indexed) loop.index0 The current iteration of the loop. (0 indexed) loop.revindex The number of iterations from the end of the loop (1 indexed) loop.revindex0 The number of iterations from the end of the loop (0 indexed) loop.first True if first iteration. loop.last True if last iteration. loop.length The number of items in the sequence.

Defined in:

liquid/blocks/for.cr

Constant Summary

GLOBAL = /(?<var>\w+) in (?<range>.+)/
RANGE = /(?<start>[0-9]+)\.\.(?<end>[0-9]+)/
VARNAME = /^\s*(?<varname>#{VAR})\s*$/

Constructors

Instance Method Summary

Instance methods inherited from class Liquid::Block::Node

<<(node : Node) <<, ==(other : self) ==, accept(visitor : Visitor) accept, children : Array(Liquid::Block::Node) children, inspect(io : IO) inspect, lstrip=(lstrip : Bool) lstrip=, lstrip? : Bool lstrip?, rstrip=(rstrip : Bool) rstrip=, rstrip? : Bool rstrip?

Constructor methods inherited from class Liquid::Block::Node

new(content : String) new

Constructor Detail

def self.new(loop_var : String, begin s, end e) #

[View source]
def self.new(loop_var : String, loop_over : Range(Int32, Int32) | String) #

[View source]
def self.new(content : String) #

[View source]

Instance Method Detail

def inspect(io : IO) #
Description copied from class Reference

Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>

[View source]
def loop_over : String | Range(Int32, Int32) #

[View source]
def loop_var : String #

[View source]