I have the following problem:Given an Array, apply a certain method x to each Array element (yielding a new Array), with the restriction that array elements which are nil, should be mapped to some default value. Method and default element are parameters. Example:Array: ['abc',nil,'defg']Method: :sizeDefault element: -1Expected result: [3, -1, 4]I implemented this by adding a method map_with to the Array class:class Array  def map_with(accessor, default_value=nil)    map {|e| e.nil? ? default_value : e.send(accessor) }  endend['abc',nil,'defg'].map_with(:size, -1)I'm looking for an improvement of my current solution. Can the solution be improved in the following sense?Provide the same result with simpler codeMake the function more flexible (more generally useful) by not adding too much code
Custom map on `Array`
ruby;functional programming;null;extension methods