An additive/pass-through hybrid overrides an existing method, calls the original implementation, and adds functionality or interface options without discarding the original behavior. section 13.2.3
A pass-through override typically follows this sequence:
- Inspect or adapt the argument when it supports an additional representation. section 13.2.3
- Call the original method with super, preserving behavior for adapted and unchanged arguments. section 13.2.3
- Extend the interface while retaining the original call when no new option is supplied. section 13.2.3
Formatting Time without losing default behavior
An older Active Support override kept Time#to_s unchanged with no arguments, while adding formats such as :db, :number, and :rfc822. The current implementation rejects the extra argument, showing that the extension was version-specific. section 13.2.3
# Layers additional behavior on DateTime#<=> so that
# Time and ActiveSupport::TimeWithZone instances
# can be compared with a DateTime.
def <=>(other)
if other.respond_to? :to_datetime
super other.to_datetime rescue nil
else
super
end
end
This override adapts comparable objects to DateTime before delegating comparison to the original <=> method. section 13.2.3
