0
Explain this code
So I was going through the ruby tutorial again just to revise stuff and there was this question What is the output of this code? class A def initialize(x) puts x/2 end end class B def initialize(y) super(y+2) end end ob=B.new(6) and the answer to this question was 4. I kinda donât understand. Can someone please explain this code line by line?
5 Answers
+ 3
B.new(6) calls B.initialize with y=6 which calls A.initialize with (y+2)=6 which calls puts with (x/2)=4
+ 1
@Gordie Haha yea I forgot that sorry
0
Oooo I get it now. Thanks!