Sha256: 5e931b094f1e24da59e1b0355b4b759858f87e02e6c155ce041e12bbaecfea66

Contents?: true

Size: 523 Bytes

Versions: 1

Compression:

Stored size: 523 Bytes

Contents

# frozen_string_literal: true

require 'set'

class Array
  # concat, # push, # add, #
  EMPTY = [].freeze

  def gather(other)
    case other
    when Array, Set then concat(other)
    when nil then self
    else self.<< other
    end
  end

  def self.wrap(value)
    case value
    when nil then EMPTY
    when Array then value
    else [value]
    end
  end

  def self.each_or_self(value, &block)
    case value
    when nil then nil
    when Array then value.each(&block)
    else block.call(value)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
leftovers-0.1.0 lib/leftovers/core_ext.rb