Sha256: cde2f6606be4b74b7d55dd04592f7b5c0b18d0b957e1e2bf72a4967764d6ebc2
Contents?: true
Size: 732 Bytes
Versions: 15
Compression:
Stored size: 732 Bytes
Contents
# frozen_string_literal: true class ReeArray::Wrap include Ree::FnDSL fn :wrap doc(<<~DOC) Wraps its argument in an array unless it is already an array (or array-like). Specifically: * If the argument is +nil+ an empty array is returned. * Otherwise, if the argument responds to +to_ary+ it is invoked, and its result returned. * Otherwise, returns an array with the argument as its single element. wrap(nil) # => [] wrap([1, 2, 3]) # => [1, 2, 3] wrap(0) # => [0] DOC contract(Any => ArrayOf[Any]) def call(object) if object.nil? [] elsif object.is_a?(Array) || object.is_a?(Enumerable) object else [object] end end end
Version data entries
15 entries across 15 versions & 1 rubygems