Skip to content

Month: October 2022

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]