环境: 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
程式也都能执行, 还是说*号有特别的意义?
小弟是新手, 没有程式底子, 请各位多指教
谢谢解惑!