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.12.0 lib/mutant/util.rb
mutant-0.11.34 lib/mutant/util.rb
mutant-0.11.33 lib/mutant/util.rb
mutant-0.11.32 lib/mutant/util.rb
mutant-0.11.31 lib/mutant/util.rb
mutant-0.11.30 lib/mutant/util.rb
mutant-0.11.29 lib/mutant/util.rb
mutant-0.11.28 lib/mutant/util.rb
mutant-0.11.27 lib/mutant/util.rb
mutant-0.11.26 lib/mutant/util.rb
mutant-0.11.25 lib/mutant/util.rb
mutant-0.11.24 lib/mutant/util.rb
mutant-0.11.23 lib/mutant/util.rb
mutant-0.11.22 lib/mutant/util.rb
mutant-0.11.21 lib/mutant/util.rb
mutant-0.11.20 lib/mutant/util.rb
mutant-0.11.19 lib/mutant/util.rb
mutant-0.11.18 lib/mutant/util.rb
mutant-0.11.17 lib/mutant/util.rb
mutant-0.11.16 lib/mutant/util.rb