saasbook

decorator_alias_method.rb

Mar 13th, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.45 KB | None | 0 0
  1. # reopen Mailer class and decorate its send_email method.
  2. class Mailer
  3.   alias_method_chain :send_email, :cc
  4.   def send_email_with_cc(recipient,body) # this is our new method
  5.     send_email_without_cc(recipient,body) # will call original method
  6.     copy_sender(body)
  7.   end
  8. end
  9. # now we have two methods:
  10. send_email(...)            # calls send_email_with_cc
  11. send_email_with_cc(...)    # same thing
  12. send_email_without_cc(...) # call (renamed) original method
Add Comment
Please, Sign In to add comment