Created
October 24, 2011 13:49
-
-
Save hyfather/1309067 to your computer and use it in GitHub Desktop.
Demonstrates how the splat operator works in Ruby.
This file contains hidden or 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
lambda{|*args| args}.call(1, 2) | |
#=> [1, 2] | |
# This is the splat operator used in the 'collecting mode'. | |
# The splat before the args ensured that all arguments were marshalled into an Array. | |
[1, 2, [3, 4]] | |
#=> [1, 2, [3, 4]] | |
[1, 2, *[3, 4]] | |
#=> [1, 2, 3, 4] | |
# This is the unmarshalling 'mode' of the splat operator. | |
# Notice how [3, 4] was 'unwrapped' into only the list of elements inside. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment