I was analyzing my friend's code, and I saw this little snippet:
n,a=*$<
I can't figure out what it means - I've searched on many sites, but they don't seem to recognize the special characters.
$<
is ARGF. From ruby's standard docummentation:
ARGF is a stream designed for use in scripts that process files given as command-line arguments or passed in via STDIN.
A super good explanation here
*
is splat operator.
You are assigning to a
and n
what's inside ARGF/STDIN at that 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.