lib/active_object/array.rb in active_object-5.7.0 vs lib/active_object/array.rb in active_object-5.8.0

- old
+ new

@@ -30,13 +30,11 @@ def delete_last! replace(delete_last) end def delete_values(*args) - result = [] - args.each { |val| result << delete(val) } - result + args.each_with_object([]) { |val, results| results << delete(val) } end def demote(value) sort_by { |val| val == value ? 0 : -1 } end @@ -118,11 +116,10 @@ padding = (number - length % number) % number collection = dup.concat(::Array.new(padding, fill_with)) end sliced_collection = collection.each_slice(number) - block_given? ? sliced_collection { |val| yield(val) } : sliced_collection.to_a end # rubocop:enable Metrics/MethodLength, Metrics/AbcSize def indexes(value) @@ -144,11 +141,13 @@ replace(nillify) end def position(value) idx = index(value) - (idx + 1) unless idx.nil? + return if idx.nil? + + idx + 1 end def positions(value) indexes(value).map { |val| val + 1 } end @@ -178,11 +177,13 @@ reject { |val| args.include?(val) } end def rposition(value) idx = rindex(value) - (idx + 1) unless idx.nil? + return if idx.nil? + + idx + 1 end def sample! delete_at(::Random.rand(length - 1)) end @@ -224,15 +225,14 @@ position >= 0 ? first(position + 1) : self[0..position] end # rubocop:disable Metrics/MethodLength def to_sentence(options = {}) - default_connectors = { + options = { words_connector: ', ', two_words_connector: ' and ', last_word_connector: ', and ' - } - options = default_connectors.merge!(options) + }.merge!(options) case length when 0 '' when 1