lib/refinements/arrays.rb in refinements-10.1.1 vs lib/refinements/arrays.rb in refinements-11.0.0
- old
+ new
@@ -31,10 +31,33 @@
def minimum(key) = map(&key).min
def pad(value, max: size) = dup.fill(value, size..(max - 1))
+ def pick(*keys)
+ return if empty?
+
+ keys.many? ? keys.map { |key| first[key] } : first[keys.first]
+ end
+
+ def pluck(*keys)
+ return dup if empty?
+ return [] if keys.empty?
+
+ if keys.many?
+ map { |element| keys.map { |key| element[key] } }
+ else
+ key = keys.first
+ map { |element| element[key] }
+ end
+ end
+
+ def replace_at(index, *elements)
+ delete_at index
+ insert(index, *elements)
+ end
+
def ring(&) = [last, *self, first].each_cons(3, &)
def supplant target, *replacements
index(target).then do |position|
delete_at position
@@ -47,15 +70,19 @@
def supplant_if target, *replacements
each { |item| supplant target, *replacements if item == target }
self
end
- def to_sentence delimiter: ", ", conjunction: "and"
+ def to_sentence conjunction = "and", delimiter: ", "
case length
when (3..) then "#{self[..-2].join delimiter}#{delimiter}#{conjunction} #{last}"
when 2 then join " #{conjunction} "
else join
end
+ end
+
+ def to_usage conjunction = "and", delimiter: ", "
+ map(&:inspect).to_sentence conjunction, delimiter:
end
end
end
end