Created
February 7, 2011 18:28
-
-
Save bagwanpankaj/814904 to your computer and use it in GitHub Desktop.
Ruby 1.9 Defining Spalt arguments
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
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
#tested with ruby 1.9.2 | |
#first argument as spalt argument. | |
def test_splat(*a, b) | |
"a:#{a},b:#{b}" | |
end | |
#So in this last argument would be assigned to b and all others would be to a | |
test(1,2,3,4,5,6) | |
#=> "a:[1, 2, 3, 4, 5],b:6 | |
#tested with ruby 1.9.2 | |
#splat arg in middle of arguments. | |
def test_splat_middle(a, *b, c) | |
"a:#{a},b:#{b},c:#{c}" | |
end | |
#So in this first argument would be assigned to a, last to c and all others would be to b | |
test_splat_middle(1,2,3,4,5,6) | |
#=> "#a:1,b:[2, 3, 4, 5],c:6" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment