module Locomotive::Steam::Liquid::Filters::Array
Public Instance Methods
in_groups_of(array, number, fill_with = nil)
click to toggle source
# File lib/locomotive/steam/liquid/filters/array.rb, line 36 def in_groups_of(array, number, fill_with = nil) return array unless array.respond_to?(:all) || array.respond_to?(:each_slice) number = number.to_i grouped_array = array.respond_to?(:all) ? array.all : array if fill_with != false # size % number gives how many extra we have; # subtracting from number gives how many to add; # modulo number ensures we don't add group of just fill. padding = (number - grouped_array.size % number) % number grouped_array = grouped_array + ::Array.new(padding, fill_with) end grouped_array.each_slice(number).to_a end
pop(array, input = 1)
click to toggle source
# File lib/locomotive/steam/liquid/filters/array.rb, line 8 def pop(array, input = 1) return array unless array.is_a?(::Array) new_ary = array.dup new_ary.pop(input.to_i || 1) new_ary end
push(array, input)
click to toggle source
# File lib/locomotive/steam/liquid/filters/array.rb, line 15 def push(array, input) return array unless array.is_a?(::Array) new_ary = array.dup new_ary.push(input) new_ary end
shift(array, input = 1)
click to toggle source
# File lib/locomotive/steam/liquid/filters/array.rb, line 22 def shift(array, input = 1) return array unless array.is_a?(::Array) new_ary = array.dup new_ary.shift(input.to_i || 1) new_ary end
unshift(array, input)
click to toggle source
# File lib/locomotive/steam/liquid/filters/array.rb, line 29 def unshift(array, input) return array unless array.is_a?(::Array) new_ary = array.dup new_ary.unshift(*input) new_ary end