Skip to content

Instantly share code, notes, and snippets.

@toothrot
Created June 25, 2010 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toothrot/453238 to your computer and use it in GitHub Desktop.
Save toothrot/453238 to your computer and use it in GitHub Desktop.
# 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
Copy link

(a,*b), *c = [[1,2,3],[3,4,5]]
=> [[1, 2, 3], [3, 4, 5]]

@evanfarrar
Copy link

b
=> [2, 3]

@thumblemonks
Copy link

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] 

@toothrot
Copy link
Author

oh, nice.

@evanfarrar
Copy link

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

@thumblemonks
Copy link

*["Nope", "Too late", "Not trying now"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment