Class: ObjectIdentifier::ArrayWrap

Inherits:
Object
  • Object
show all
Defined in:
lib/object_identifier.rb

Overview

ObjectIdentifier::ArrayWrap mirrors the implementation of Rails’ Array.wrap method. This allows us to get around objects that respond to ‘to_a` (such as Struct) and, instead, either utilize `to_ary` or just actually wrap the object in an Array ourselves.

Class Method Summary collapse

Class Method Details

.call(object) ⇒ Object

:reek:NilCheck :reek:ManualDispatch



132
133
134
135
136
137
138
139
140
# File 'lib/object_identifier.rb', line 132

def self.call(object)
  if object.nil?
    []
  elsif object.respond_to?(:to_ary)
    object.to_ary || [object]
  else
    [object]
  end
end