環境: Ruby 2.0.0p0
我在Learn Ruby The Hard Way的第18個練習裡有一些小疑問想請教
http://ruby.learncodethehardway.org/book/ex18.html
# this one is like your scripts with argv
def puts_two(*args)
arg1, arg2 = args
puts "arg1: #{arg1}, arg2: #{arg2}"
end
# ok, that *args is actually pointless, we can just do this
def puts_two_again(arg1, arg2)
puts "arg1: #{arg1}, arg2: #{arg2}"
end
作者說 *args 其實是 pointless, 但是程式仍然可以執行?
那*args的意義到底是?
因為我如果把*args換成任意的*____ , 比如說:
def puts_two(*a)
arg1, arg2 = a
puts "arg1: #{arg1}, arg2: #{arg2}"
end
程式也都能執行, 還是說*號有特別的意義?
小弟是新手, 沒有程式底子, 請各位多指教
謝謝解惑!