Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Module
- def before_method method, &block
- alias_method "__old__#{method.to_s}".to_sym, method unless respond_to? "__old__#{method.to_s}".to_sym
- define_method method do |*args|
- block.call(*args)
- send "__old__#{method.to_s}".to_sym, *args
- end
- end
- end
- class Test
- def greet who
- puts "hello #{who}"
- end
- end
- Test.before_method :greet do |w|
- puts "Calling a greeting for #{w}"
- end
- b = Test.new
- b.greet "world"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement