ruby - What does *args mean? -


this question has answer here:

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

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -