ruby 方法参数中*的表示

class Roulette
  def start(*args)
    puts args
    puts '+++++++++++++++++++++'
    puts args.length
    puts '+++++++++++++++++++++'
    puts args.to_s
  end
end
obj = Roulette.new
obj.start(%w(xiaoming xiaofang xiaohong))

1.png
class Roulette
  def start(*args)
    puts args
    puts '+++++++++++++++++++++'
    puts args.length
    puts '+++++++++++++++++++++'
    puts args.to_s
  end
end
obj = Roulette.new
obj.start(%w(xiaoming xiaofang xiaohong), 'xiaoyao')

2.png

你可能感兴趣的:(ruby 方法参数中*的表示)