Class: Array
- Defined in:
- lib/lh/core_extensions/array/to_h.rb,
lib/lh/core_extensions/array/raise_if_empty.rb,
lib/lh/core_extensions/array/raise_if_item_nil.rb
Instance Method Summary collapse
-
#raise_if_empty(message = "Array must not be empty.") ⇒ Object
Raises an ArgumentError if the array is empty (contains no items at all, nil objects count as item).
-
#raise_if_item_nil(message = nil) ⇒ Object
Raises an ArgumentError if the array contains any item that is nil.
- #to_h ⇒ Object
Instance Method Details
#raise_if_empty(message = "Array must not be empty.") ⇒ Object
Raises an ArgumentError if the array is empty (contains no items at all, nil objects count as item).
7 8 9 |
# File 'lib/lh/core_extensions/array/raise_if_empty.rb', line 7 def raise_if_empty( = "Array must not be empty.") raise ArgumentError.new() if self.empty? end |
#raise_if_item_nil(message = nil) ⇒ Object
Raises an ArgumentError if the array contains any item that is nil.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lh/core_extensions/array/raise_if_item_nil.rb', line 9 def raise_if_item_nil( = nil) indices_w_nil_values = [] each_index do |index| indices_w_nil_values << index if self[index].nil? end unless indices_w_nil_values.empty? raise ArgumentError.new() if = "Objects at position #{indices_w_nil_values.join(", ")} are nil" raise ArgumentError.new() end end |