Created
December 10, 2013 23:00
-
-
Save dogweather/7901986 to your computer and use it in GitHub Desktop.
Define a method with a variable length argument list
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
| func(1, 2, 3, 4, 5) | |
| # The argument with the "splat operator" denotes | |
| # a variable number of arguments which will be | |
| # placed into an array. | |
| def func(arg1, arg2, *other_args) | |
| p arg1.inspect # => 1 | |
| p arg2.inspect # => 2 | |
| p other_args.inspect # => [3, 4, 5] | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment