Module: Mutant::Util Private
- Defined in:
- lib/mutant/util.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Utility methods
Constant Summary collapse
- SizeError =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Error raised by ‘Util.one` if size is less than zero or greater than one
Class.new(IndexError)
Class Method Summary collapse
-
.max_one(array) ⇒ Object?
private
Return only element in array if it contains max one member.
-
.one(array) ⇒ Object
private
Return only element in array if it contains exactly one member.
Class Method Details
.max_one(array) ⇒ Object?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return only element in array if it contains max one member
rubocop:disable Lint/EmptyInPattern
31 32 33 34 35 36 37 38 39 |
# File 'lib/mutant/util.rb', line 31 def self.max_one(array) case array in [] in [value] value else fail SizeError, "expected size to be max 1 but size was #{array.size}" end end |
.one(array) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return only element in array if it contains exactly one member
14 15 16 17 18 19 20 21 |
# File 'lib/mutant/util.rb', line 14 def self.one(array) case array in [value] value else fail SizeError, "expected size to be exactly 1 but size was #{array.size}" end end |