ruby - What does *args mean? -
this question has answer here:
- what (unary) * operator in ruby code? 3 answers
what args mean, , different between , argv if there difference?
def puts_two(*args) arg1, arg2 = args puts "arg1: #{arg1}, arg2: #{arg2}" end
argv special variable in ruby. contains arguments passed script on command line. example, if write following code in file called test.rb:
argv.each |a| puts end and call this
c:\> ruby test.rb 1 2 will display
one 2 in code posted, *args indicates method accepts variable number of arguments in array called args. have been called want (following ruby naming rules, of course).
so in case, args totally unrelated argv.
Comments
Post a Comment