Module: CMDx::Utils::Wrap

Extended by:
Wrap
Included in:
Wrap
Defined in:
lib/cmdx/utils/wrap.rb

Overview

Provides array wrapping utilities for normalizing input values into consistent array structures.

Instance Method Summary collapse

Instance Method Details

#array(object) ⇒ Array

Wraps an object in an array if it is not already an array.

Examples:

Already an array

Wrap.array([1, 2, 3])
# => [1, 2, 3]

Single value

Wrap.array(1)
# => [1]

Nil value

Wrap.array(nil)
# => []

Parameters:

  • object (Object)

    The object to wrap in an array

Returns:

  • (Array)

    The wrapped array

Rbs:

  • (untyped object) -> Array



28
29
30
31
32
33
34
# File 'lib/cmdx/utils/wrap.rb', line 28

def array(object)
  case object
  when Array then object
  when NilClass then EMPTY_ARRAY
  else Array(object)
  end
end