RUBY   17

lines to array

Guest on 21st August 2022 08:31:54 AM

  1. #!/usr/bin/env ruby
  2. # Converts lines from a file into an array of strings.
  3. if ARGV.size == 0
  4.         puts "lines_to_array.rb <file>"
  5. else
  6.         lines = File.readlines(ARGV[0])
  7.         lines = lines.map do |line|
  8.                 "'" + line.strip + "'"
  9.         end
  10.         puts '[' + lines.join(',') + ']'
  11. end

Raw Paste


Login or Register to edit or fork this paste. It's free.