Skip to content

Instantly share code, notes, and snippets.

@pechorin
Created May 13, 2012 10:31
Show Gist options
  • Save pechorin/2687648 to your computer and use it in GitHub Desktop.
Save pechorin/2687648 to your computer and use it in GitHub Desktop.
proxy
class Image
def after_save
puts "after save image!"
end
end
img = Image.new
img.after_save # => "after save image!"
# а теперь прокся :D
Image.class_eval do
def after_save_proxy
old_after_save
puts "this is proxy call! :)"
end
alias :old_after_save :after_save
alias :after_save :after_save_proxy
end
img_with_proxy = Image.new
img_with_proxy.after_save # => "after save image!"
# => "this is proxy call! :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment