Module: Genericode::Utils Private
- Defined in:
- lib/genericode/utils.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Utility functions
Class Method Summary collapse
-
.array_wrap(object) ⇒ Array
private
Wraps object in an array unless it is already an array (or array-like).
-
.one_or_all(array) ⇒ Object, Array
private
Returns either the only element of the array or the array itself.
Class Method Details
.array_wrap(object) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Wraps object in an array unless it is already an array (or array-like)
23 24 25 26 27 28 29 30 31 |
# File 'lib/genericode/utils.rb', line 23 def self.array_wrap(object) if object.nil? [] elsif object.respond_to?(:to_ary) object.to_ary else [object] end end |
.one_or_all(array) ⇒ Object, Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns either the only element of the array or the array itself
46 47 48 |
# File 'lib/genericode/utils.rb', line 46 def self.one_or_all(array) array.one? ? array.first : array end |