Created
May 27, 2014 13:13
-
-
Save shinokada/5cff7a0191dff897484e 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
# strange splat | |
[*0..9] # [1,2,3,4,5,6,7,8,9] | |
# http://endofline.wordpress.com/2011/01/21/the-strange-ruby-splat/ | |
# splat creates an array | |
first, *list = [1,2,3,4] # first= 1, list= [2,3,4] | |
*list, last = [1,2,3,4] # list= [1,2,3], last= 4 | |
first, *center, last = [1,2,3,4] # first= 1, center= [2,3], last=4 | |
a = *"Hello" #=> ["Hello"] | |
"Hello".to_a #=> NoMethodError: undefined method `to_a' for "Hello":String | |
a = *(1..3) #=> [1, 2, 3] | |
a = *[1,2,3] #=> [1, 2, 3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment