Filecrossjoin.rb

This content was produced by an LLM and could include errors.

This script processes command-line arguments, reading multiple text files and then combining the corresponding lines into a single, comma-separated output stream, effectively creating tabular data from various sources.

def read_lines(path)
  File.readlines(path, chomp: true)
end
#=> :read_lines

arrays = ARGV.map { |path| read_lines(path) }
#=> []

#abort "Please specify at least one file." if arrays.empty?
#=> nil

first, *rest = arrays
#=> []
first, *rest = ("a".."b").to_a, 2.times.to_a, ("x".."y").to_a # for presentation only (remove later)
#=> [["a", "b"], [0, 1], ["x", "y"]]
first.product(*rest) do |*row|
  puts row.join(",")
end
a,0,x
a,0,y
a,1,x
a,1,y
b,0,x
b,0,y
b,1,x
b,1,y
#=> ["a", "b"]


Ruby 4.0.5