[問題] LRTHW ex18 疑問
環境: 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
程式也都能執行, 還是說*號有特別的意義?
小弟是新手, 沒有程式底子, 請各位多指教
謝謝解惑!
--
http://www.facebook.com/AdJudge
廣告, 創意無限
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 1.164.49.131
→
04/09 06:21, , 1F
04/09 06:21, 1F
→
04/09 11:02, , 2F
04/09 11:02, 2F
→
04/09 14:22, , 3F
04/09 14:22, 3F
→
04/09 21:08, , 4F
04/09 21:08, 4F
→
04/09 21:09, , 5F
04/09 21:09, 5F
→
04/09 22:32, , 6F
04/09 22:32, 6F
→
04/09 22:32, , 7F
04/09 22:32, 7F
Ruby 近期熱門文章
PTT數位生活區 即時熱門文章