super gọi implementation tiếp theo của cùng method name trong ancestor chain.
1 | class Animal |
Truyền argument
1 | super # forward toàn bộ argument và block hiện tại |
Khác biệt giữa super và super() nhỏ về ký tự, lớn về behavior.
Module cũng nằm trong chain
1 | module Logging |
Với prepend, module đứng trước class; super đi tiếp vào implementation của class. Vì vậy nói super luôn gọi “parent class” là thiếu: nó gọi next method theo lookup chain.
Constructor
1 | class Admin < User |
Forward mù toàn bộ keyword có thể làm parent nhận argument không biết. Explicit forwarding rõ hơn khi signature khác nhau.
Debug
1 | method(:call).owner |
Nếu super raise “no superclass method”, xem owner/ancestors trước khi thêm method rỗng chỉ để lỗi im. super là navigation trong lookup chain; không có điểm tiếp theo thì Ruby không tự xây đường.