Q:

Read a file with ruby to two variables directly

with How can I read a file with Ruby?, read file then print it one line by one line. 
But my request is different.
I have a txt file with similar content of thousand lines.
ABC 123
XYZ 234

So with below code, I can print the whole lines.
File.open("input.txt", "r") do |infile|
    while (line = infile.gets)
        puts "#{counter}: #{line}"
        counter = counter + 1
    end
end

But I need something to assign column1 to A, and column2 to B directly:
File.open("input.txt", "r").each_line do |A B|
        puts "#{A} has the value of #{B}"
end

How can I do that.
Generally, I need a ruby function as in bash scripting:
#!/usr/bin/env bash

while read A B 
do
  echo "$A has the value of $B"
done < input.txt

A:

As long as you don't need to store the values for future reference you can pretty easily split the line at the space and use it as an array to pull both variables. Also, if you iterate with each line it will save you the possibilities of minor errors in the loops, but you can always replace it with a loop. 
File.open("my/file/path", "r").each_line do |line|
  vars=line.split(" ")
  puts "#{vars[0]} has the value of #{vars[1]}"
end

