Class: Class
- Inherits:
-
Object
- Object
- Class
- Defined in:
- lib/method_wrapper.rb
Instance Method Summary collapse
Instance Method Details
#wrap_instance_method(pattern:, &wrapper) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/method_wrapper.rb', line 9 def wrap_instance_method(pattern:, &wrapper) instance_methods.grep(pattern).each do |name| method = instance_method(name) define_method(name) { |*args, &block| wrapper.call(method.bind(self), *args, &block) } end end |
#wrap_method(pattern:, &wrapper) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/method_wrapper.rb', line 2 def wrap_method(pattern:, &wrapper) methods.grep(pattern).each do |name| method = method(name) define_singleton_method(name) { |*args, &block| wrapper.call(method, *args, &block) } end end |