Created
April 18, 2018 07:27
-
-
Save samgooi4189/a2f214699de0133261db0f77d954ed34 to your computer and use it in GitHub Desktop.
method definition in ruby, colon vs equals
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
$ irb | |
2.4.3 :001 > def foo(a:1, b:2) | |
2.4.3 :002?> print "#{a}#{b}" | |
2.4.3 :003?> end | |
=> :foo | |
2.4.3 :004 > def foobar(a:1, b:2) | |
2.4.3 :005?> foo(a,b) | |
2.4.3 :006?> end | |
=> :foobar | |
2.4.3 :007 > foobar(3,4) | |
ArgumentError: wrong number of arguments (given 2, expected 0) | |
from (irb):4:in `foobar' | |
from (irb):7 | |
from /home/samgooi4189/.rvm/rubies/ruby-2.4.3/bin/irb:11:in `<main>' | |
2.4.3 :008 > | |
2.4.3 :009 > | |
2.4.3 :010 > | |
2.4.3 :011 > def hello(a=1, b=2) | |
2.4.3 :012?> print "#{a}#{b}" | |
2.4.3 :013?> end | |
=> :hello | |
2.4.3 :014 > def helloworld(a=1, b=2) | |
2.4.3 :015?> hello(a,b) | |
2.4.3 :016?> end | |
=> :helloworld | |
2.4.3 :017 > helloworld(3,4) | |
34 => nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2.4.3 :016 > def hello(a=1, b=2)
2.4.3 :017?> print "#{a}#{b}"
2.4.3 :018?> end
=> :hello
2.4.3 :019 > def helloworld(a=1, b=2)
2.4.3 :020?> hello(a, b)
2.4.3 :021?> end
=> :helloworld
2.4.3 :022 > helloworld(3, b:4)
3{:b=>4} => nil