Sha256: c8c4c2e79218dda24d4d74de5ff81513cf0da4b5e787efd89b9a5e66c0f5ffae

Contents?: true

Size: 488 Bytes

Versions: 6

Compression:

Stored size: 488 Bytes

Contents

module Mutant
  # Utility methods
  module Util
    # Error raised by `Util.one` if size is less than zero or greater than one
    SizeError = Class.new(IndexError)

    # Return only element in array if it contains exactly one member
    #
    # @param array [Array]
    #
    # @return [Object] first entry
    def self.one(array)
      return array.first if array.one?

      fail SizeError, "expected size to be exactly 1 but size was #{array.size}"
    end
  end # Util
end # Mutant

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mutant-0.8.16 lib/mutant/util.rb
mutant-0.8.15 lib/mutant/util.rb
mutant-0.8.14 lib/mutant/util.rb
mutant-0.8.13 lib/mutant/util.rb
mutant-0.8.12 lib/mutant/util.rb
mutant-0.8.11 lib/mutant/util.rb