Range extraction: convert a comma separated list of integers into range format

To convert a comma separated list of integers into range format in Ruby, you can follow these steps:

  1. Split the input string into an array of integers using the split method and the comma as the separator.
  2. Convert the array of integers into a range using the each_cons method to iterate over consecutive elements and the slice_when method to group them into ranges.
  3. Map the ranges to strings using the map method and the join method to create the final range format string.