Skip to content

Instantly share code, notes, and snippets.

@ziyan-junaideen
Last active September 7, 2022 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziyan-junaideen/be8f3fcf11639fc311032796bef99d0e to your computer and use it in GitHub Desktop.
Save ziyan-junaideen/be8f3fcf11639fc311032796bef99d0e to your computer and use it in GitHub Desktop.
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>'
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