Mar*_*une 13
splat将尝试将对象显式转换为Array.
为此,它将发送to_a并期望Array结果.
class Foo
  def to_a
    [1,2,3]
  end
end
a, b, c = *Foo.new
a # => 1
如果对象没有响应to_a,则没有效果,例如[*42] == [42]
许多内置类实现to_a.特别是:
Enumerable)
ArrayHashRangeIO 和 FileEnumeratorEnumerator::Lazy (Ruby 2.0)Set 和 SortedSetNilClassMatchDataOpenStructStructTimeMatrix 和 Vector因此,所有这些都可以被喷溅:
match, group, next_group = *"Hello, world".match(/(.*), (.*)/)
group # => "Hello"
| 归档时间: | 
 | 
| 查看次数: | 4180 次 | 
| 最近记录: |