Created
July 21, 2016 14:33
-
-
Save burlesona/ca15d7e9f5b05abd7e07be4b57c3ac7f to your computer and use it in GitHub Desktop.
Ruby Method Fun
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
# BEFORE RUBY 2.0 | |
def method(argument,hash) | |
end | |
method 1, :foo => "bar", :baz => "qux" | |
method 1, {:foo => "bar", :baz => "qux"} #identical | |
method(1, {:foo => "bar", :baz => "qux"}) #identical | |
def method(v1=1,v2=2,v3=3) | |
end | |
method # v1=1, v2=2, v3=3 | |
method 10 #v1=10, v2=2, v3=3 | |
method 10, 20 #v1=10, v2=20, v3=3 | |
method 10, 20, 30 #v1=10, v2=20, v3=30 | |
# BEFORE RUBY 2.1 | |
def method(a=1,b:2,c:3) | |
end | |
method # a=1, b=2, c=3 | |
method 10 # a=10, b=2, c=3 | |
method 10, b: 20 # a=10, b=20, c=3 | |
method 10, b: 20, c: 30 # a=10, b=20, c=30 | |
method 10, 20, 30 # ArgumentError | |
# SINCE RUBY 2.1 | |
def method(a,b:,c:) | |
end | |
method # argument error | |
method 10 # argument error | |
method 10, b: 20 # argument error | |
method 10, b: 20, c: 30 # a=10, b=20, c=30 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment