-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargv.rb
16 lines (10 loc) · 1.14 KB
/
argv.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
first, second, third = ARGV # Argument variable
puts "Your first variable is: #{first}"
puts "Your second variable is: #{second}"
puts "Your third variable is: #{third}"
# he ARGV is the "argument variable," a very standard name in programming that you will find used in many other languages. This variable holds the arguments you pass to your Ruby script when you run it. In the exercises you will get to play with this more and see what happens.
# Line 1 "unpacks" ARGV so that, rather than holding all the arguments, it gets assigned to three variables you can work with: first, second, and third. This may look strange, but "unpack" is probably the best word to describe what it does. It just says, "Take whatever is in ARGV, unpack it, and assign it to all of these variables on the left in order."
# To run:
# $ ruby ex13.rb first 2nd 3rd
# You should use $stdin.gets.chomp from now on since the action gets.chomp has problems with ARGV.
# Now that you are using $stdin.gets.chomp (see #3) you can add ARGV to your script to get something from the user. Don't over think this. Just use ARGV to get one thing, then $stdin.gets.chomp to get something else.