Advertisement
Guest User

Untitled

a guest
Feb 20th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.32 KB | None | 0 0
  1. class A
  2.   def extend_me(x)
  3.     x + 1
  4.   end
  5. end
  6.  
  7. # We need to change the way our method works, but retain the original behavior
  8. # too.
  9. class A
  10.   old_method = public_instance_method(:extend_me)
  11.   define_method(:extend_me) do |x|
  12.     puts "Inside the new version"
  13.     x *= 3
  14.     old_method.bind(self).call(x)
  15.   end
  16. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement