Sha256: 41e75f9ff7390fa32dea4c72f5806c07ac388897da447a41059098dea5429fbc

Contents?: true

Size: 595 Bytes

Versions: 1

Compression:

Stored size: 595 Bytes

Contents

module Enumerable

  # Checks that the Enumerable is not empty, and returns the Enumerable
  # unmodified.  If the Enumerable fails this check, an exception is
  # raised.
  #
  # @example
  #   [7, 8].refute_empty!  # == [7, 8]
  #   [].refute_empty!      # raises exception
  #
  # @param name [String, Symbol]
  #   optional name to include in the error message
  # @return [self]
  # @raise [MiniSanity::Error]
  #   if the Enumerable is empty
  def refute_empty!(name = nil)
    if self.empty?
      raise MiniSanity::Error.new("#{name || self.class} is empty")
    end
    self
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mini_sanity-1.0.0 lib/mini_sanity/enumerable.rb