Skip to content

Ruby super

class A
   def foo 
      [1, 2, 3]
   end 
end

class B < A 
   def foo 
      super.map{ |n| n * 2 } 
   end 
end

puts A.new.foo.to_s
puts B.new.foo.to_s

Output

[1, 2, 3]
[2, 4, 6]
Published inenglish

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *