Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adrianmarino/ruby-method-wrapper
Allow intercept method invocations. Useful for log, cache, etc...
https://github.com/adrianmarino/ruby-method-wrapper
Last synced: 1 day ago
JSON representation
Allow intercept method invocations. Useful for log, cache, etc...
- Host: GitHub
- URL: https://github.com/adrianmarino/ruby-method-wrapper
- Owner: adrianmarino
- Created: 2015-10-31T20:03:27.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-23T20:06:57.000Z (almost 9 years ago)
- Last Synced: 2023-02-27T13:46:48.413Z (almost 2 years ago)
- Language: Ruby
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/adrianmarino/ruml.svg?branch=master)](https://travis-ci.org/adrianmarino/ruby_method_wrapper)
[![License](http://img.shields.io/:license-mit-blue.svg)](http://badges.mit-license.org)# ruby-method-wrapper
Allow intercept method invocations. Useful for log, cache, etc...
## Usage
Step 1: Include in your Gemfile.
```ruby
gem 'ruby_method_wrapper'
```Step 2: Write an example.
```ruby
require 'bundler/setup'
require 'method_wrapper'class Bob
def say_hello
puts "Hello!"
end
endBob.wrap_instance_method(pattern: /^say_hello$/, & ->(method, *args, &block) do
puts "Before call #{method.name}"
method.call(*args, &block)
puts "After call #{method.name}"
end)Bob.new.say_hello
```Also is possible:
* Invoke private and protected methods.
* Invoke class methods.
* Replace method call with another implementation.