Class: Serega::SeregaUtils::CollectionDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/utils/collection_detector.rb

Overview

Utility to check if an object should be serialized as a collection.

Hashes and Structs are Enumerable, but enumerate their own member values, so they are treated as single objects.

Class Method Summary collapse

Class Method Details

.call(object) ⇒ Boolean

Checks if provided object is a collection of objects

Parameters:

  • object (Object)

    Serialized object

Returns:

  • (Boolean)

    whether object should be serialized as a collection



22
23
24
# File 'lib/serega/utils/collection_detector.rb', line 22

def call(object)
  object.is_a?(Enumerable) && !object.is_a?(Hash) && !object.is_a?(Struct)
end