Sha256: b610d0d9256cbb3565f8930ab36a0b283b5bfd3a160159e923db15ba6c8469e6

Contents?: true

Size: 519 Bytes

Versions: 93

Compression:

Stored size: 519 Bytes

Contents

# frozen_string_literal: true

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

93 entries across 93 versions & 1 rubygems

Version Path
mutant-0.9.4 lib/mutant/util.rb
mutant-0.9.3 lib/mutant/util.rb
mutant-0.9.2 lib/mutant/util.rb
mutant-0.9.1 lib/mutant/util.rb
mutant-0.9.0 lib/mutant/util.rb
mutant-0.8.24 lib/mutant/util.rb
mutant-0.8.23 lib/mutant/util.rb
mutant-0.8.22 lib/mutant/util.rb
mutant-0.8.21 lib/mutant/util.rb
mutant-0.8.20 lib/mutant/util.rb
mutant-0.8.19 lib/mutant/util.rb
mutant-0.8.18 lib/mutant/util.rb
mutant-0.8.17 lib/mutant/util.rb