What does * $ <mean in Ruby mean?

I parsed my friend's code and I saw this little snippet:

n,a=*$<

I can’t understand what this means - I searched on many sites, but they do not seem to recognize special characters.

+4
source share
1 answer

$<is ARGF. From the ruby ​​standard documentation:

ARGF is a stream intended for use in scripts that process files specified as command line arguments or passed through STDIN.

Good explanation here

* is a splat operator.

You assign aand nwhat's inside ARGF / STDIN at this point.

Example:

raducroitoru@dotix ~$ cat a.txt                                         
a
b
c

raducroitoru@dotix ~$ cat a.rb                                          
a, n = *$<
puts "a is: #{a}"
puts "n is: #{n}"

raducroitoru@dotix ~$ ruby a.rb a.txt                                   
a is: a
n is: b
+4
source

Source: https://habr.com/ru/post/1680214/


All Articles