Last active
September 3, 2020 13:18
-
-
Save skatenerd/b401dfe1db3a1d405958edb48112877f to your computer and use it in GitHub Desktop.
splat confusion
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
irb(main):014:0> def low(a,b) | |
irb(main):015:1> a+b | |
irb(main):016:1> end | |
=> :low | |
irb(main):017:0> def high(*args, **kwargs) | |
irb(main):018:1> low(*args, **kwargs) | |
irb(main):019:1> end | |
=> :high | |
irb(main):020:0> high(1,2) | |
=> 3 | |
irb(main):021:0> class Low | |
irb(main):022:1> def initialize(a,b) | |
irb(main):023:2> @a = a | |
irb(main):024:2> end | |
irb(main):025:1> end | |
=> :initialize | |
irb(main):026:0> def broken_high(*args, **kwargs) | |
irb(main):027:1> Low.new(*args, **kwargs) | |
irb(main):028:1> end | |
=> :broken_high | |
irb(main):029:0> broken_high(1,2) | |
Traceback (most recent call last): | |
5: from /usr/bin/irb:11:in `<main>' | |
4: from (irb):29 | |
3: from (irb):27:in `broken_high' | |
2: from (irb):27:in `new' | |
1: from (irb):22:in `initialize' | |
ArgumentError (wrong number of arguments (given 3, expected 2)) | |
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
irb(main):012:0> class Foo | |
irb(main):013:1> def initialize | |
irb(main):014:2> end | |
irb(main):015:1> end | |
=> :initialize | |
irb(main):016:0> Foo.new(**{}) | |
=> #<Foo:0x000055e2f66e9a18> | |
irb(main):017:0> h={} | |
=> {} | |
irb(main):018:0> Foo.new(**h) | |
Traceback (most recent call last): | |
4: from /usr/bin/irb:11:in `<main>' | |
3: from (irb):18 | |
2: from (irb):18:in `new' | |
1: from (irb):13:in `initialize' | |
ArgumentError (wrong number of arguments (given 1, expected 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment