Created
June 25, 2010 18:28
-
-
Save toothrot/453238 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# via jaknowlden: | |
irb(main):001:0> (k, v), *rest = [[1,2], [3,4], [5,6]] | |
=> [[1, 2], [3, 4], [5, 6]] | |
irb(main):002:0> k | |
=> 1 | |
irb(main):003:0> v | |
=> 2 | |
irb(main):004:0> rest | |
=> [[3, 4], [5, 6]] |
evanfarrar
commented
Jun 25, 2010
b
=> [2, 3]
ruby-1.9.1-p378 > (k, v), rest = [[1,2], [3,4], [5,6]]
=> [[1, 2], [3, 4], [5, 6]]
ruby-1.9.1-p378 > rest
=> [3,4]
If you *rest
in the assignment rest => [[3, 4], [5, 6]]
. Also just tried your thingie a got different results:
ruby-1.9.1-p378 > (a,b), c = [[1,2,3],[3,4,5]]
=> [[1, 2, 3], [3, 4, 5]]
ruby-1.9.1-p378 > a
=> 1
ruby-1.9.1-p378 > b
=> 2
ruby-1.9.1-p378 > c
=> [3, 4, 5]
oh, nice.
stupid formatting erased my splat, i was just showing that you can use another splat inside
(a,*b),*c = [[1,2,3],[3,4,5]] => [[1, 2, 3], [3, 4, 5]]
then you will get the same result as me
*["Nope", "Too late", "Not trying now"]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment