"abcd".reverse # => "dcba" "abcd".invert # => NoMethodError module Reversable # klass == String here def self.included(klass) = klass.alias_method(:invert, :reverse) end
When the Reversable
module is included in a class, then the invert
alias is automatically added to the including class through the included
hook method
String.include Reversable # triggers a call to Reversable.included(String) "abcd".reverse # => "dcba" "abcd".invert # => "dcba"