Created
July 16, 2015 19:35
-
-
Save dholdren/831992922c0cf366e9d9 to your computer and use it in GitHub Desktop.
Fun with named parameters
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
def foo(x=nil, a: x, b: nil) | |
[a,b] | |
end | |
#one, un-named arg assigns to a | |
foo("a val") # => ["a val", nil] | |
#named parameter "a" assigns to a | |
foo(a: "a val") # => ["a val", nil] | |
#named parameter "b" assigns to b | |
foo(b: "b val") # => [nil, "b val"] | |
#what about using all of them? | |
foo("a val 1", a: "a val 2", b: "b val") # => ["a val 2", "b val"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment