Sha256: d92b8ee4327d051179635063c0ba2df0d564fafe7a21e58a7ac9076ca6e75744
Contents?: true
Size: 716 Bytes
Versions: 109
Compression:
Stored size: 716 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 else [object] end end end
Version data entries
109 entries across 109 versions & 1 rubygems