Closed ilyakava closed 9 years ago
Sure! Could you send a PR with this?! Thanks @ilyakava !
What's more, we can leave off parentheses(if we would like to do so):
head, *tail = array
Nice trick, could you guys send that via PR? What do you think?
How do you feel about using this monstrosity to demonstrate the generality of Ruby's destructuring semantics?
_,(_,_,((_,(foo,_)),_)) = [1, [2, [3, 4], [[5, [:target], 6], [7], 8, [9], 10]]]
foo # => :target
Hey @0x0dea , I was thinking about your example. Why do you think it could be trick?
More about this @ilyakava - http://devblog.avdi.org/2010/01/31/first-and-rest-in-ruby/
I don't know if this is "tricky" enough but I thought this was cool
(head, *tail) = array # break off the first element of the array, and keep the rest separately
source