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.10.11 lib/mutant/util.rb
mutant-0.10.10 lib/mutant/util.rb
mutant-0.10.9 lib/mutant/util.rb
mutant-0.10.8 lib/mutant/util.rb
mutant-0.10.7 lib/mutant/util.rb
mutant-0.10.6 lib/mutant/util.rb
mutant-0.10.5 lib/mutant/util.rb
mutant-0.10.4 lib/mutant/util.rb
mutant-0.10.1 lib/mutant/util.rb
mutant-0.10.0 lib/mutant/util.rb
mutant-0.9.14 lib/mutant/util.rb
mutant-0.9.13 lib/mutant/util.rb
mutant-0.9.12 lib/mutant/util.rb
mutant-0.9.11 lib/mutant/util.rb
mutant-0.9.10 lib/mutant/util.rb
mutant-0.9.9 lib/mutant/util.rb
mutant-0.9.8 lib/mutant/util.rb
mutant-0.9.7 lib/mutant/util.rb
mutant-0.9.6 lib/mutant/util.rb
mutant-0.9.5 lib/mutant/util.rb