Last active
September 7, 2022 17:00
-
-
Save ziyan-junaideen/be8f3fcf11639fc311032796bef99d0e to your computer and use it in GitHub Desktop.
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
class A | |
def initialize(a:) | |
puts("Initailize A: #{a}") | |
end | |
end | |
class B < A | |
def initialize(a:, b:) | |
puts("Initailize B: #{b}") | |
super(a) | |
end | |
end | |
class C < B | |
def initialize(a:, b:, c:) | |
puts("Initailize C: #{c}") | |
super(a, b) | |
end | |
end | |
c = C.new(a: 1, b: 2, c: 3) | |
⇒ ruby test.rb | |
Initailize C: 3 | |
test.rb:8:in `initialize': wrong number of arguments (given 2, expected 0; required keywords: a, b) (ArgumentError) | |
from test.rb:17:in `initialize' | |
from test.rb:21:in `new' | |
from test.rb:21:in `<main>' |
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
class A | |
def initialize(a) | |
puts("Initailize A: #{a}") | |
end | |
end | |
class B < A | |
def initialize(a, b) | |
puts("Initailize B: #{b}") | |
super(a) | |
end | |
end | |
class C < B | |
def initialize(a, b, c) | |
puts("Initailize C: #{c}") | |
super(a, b) | |
end | |
end | |
⇒ ruby test.rb | |
Initailize C: 3 | |
Initailize B: 2 | |
Initailize A: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment