Method: Liquid::StandardFilters#compact

Defined in:
lib/liquid/standardfilters.rb

#compact(input, property = nil) ⇒ Object



557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# File 'lib/liquid/standardfilters.rb', line 557

def compact(input, property = nil)
  ary = InputIterator.new(input, context)

  if property.nil?
    ary.compact
  elsif ary.empty? # The next two cases assume a non-empty array.
    []
  else
    ary.reject do |item|
      item[property].nil?
    rescue TypeError
      raise_property_error(property)
    rescue NoMethodError
      return nil unless item.respond_to?(:[])
      raise
    end
  end
end