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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -