You can write an Around Alias in three simple steps:
1. You alias a method.
2. You redefine it.
3. You call the old method from the new method.
Example:
class String
alias :orig_length :length
def length
"Length of string '#{self}' is: #{orig_length}"
end
end
"abc".length => "Length of string 'abc' is: 3"
No comments:
Post a Comment