A splat on a hash converts it into an array.
[*{foo: :bar}] # => [[:foo, :bar]]
Is there some hidden mechanism (such as implicit class cast) going on here, or is it a built-in primitive feature?
Besides an array, are
nil
and hash the only things that disappear/change with the splat operator under Ruby 1.9?
相关问题
- What means in Dart static type and why it differs
- facebook error invalid key hash for some devices
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
相关文章
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Notice: Undefined property - how do I avoid that m
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
- Bcrypt vs Hash in laravel
A splat will attempt an explicit conversion of an object to an Array.
To do this, it will send
to_a
and expect anArray
as a result.If the object does not respond to
to_a
, then there is no effect, e.g.[*42] == [42]
Many builtin classes implement
to_a
. In particular:Enumerable
)Array
Hash
Range
IO
andFile
Enumerator
Enumerator::Lazy
(Ruby 2.0)Set
andSortedSet
NilClass
MatchData
OpenStruct
Struct
Time
Matrix
andVector
All these can thus be splatted: