https://github.com/shioyama/method_found
Intercept method_missing calls and do something useful.
https://github.com/shioyama/method_found
ruby
Last synced: about 1 year ago
JSON representation
Intercept method_missing calls and do something useful.
- Host: GitHub
- URL: https://github.com/shioyama/method_found
- Owner: shioyama
- License: mit
- Created: 2017-04-16T12:50:08.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-12-29T13:48:37.000Z (over 5 years ago)
- Last Synced: 2025-03-15T02:39:28.240Z (about 1 year ago)
- Topics: ruby
- Language: Ruby
- Size: 44.9 KB
- Stars: 16
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# MethodFound
[][gem]
[][travis]
[gem]: https://rubygems.org/gems/method_found
[travis]: https://travis-ci.org/shioyama/method_found
[docs]: http://www.rubydoc.info/gems/method_found
Intercept `method_missing` and do something useful with it.
## Installation
Add to your Gemfile:
```ruby
gem 'method_found', '~> 0.1.6'
```
And bundle it.
## Usage
Include an instance of `MethodFound::Builder` with a block defining all
patterns to match. Identify a pattern with the `intercept` method, like this:
```ruby
class Foo
include MethodFound::Builder.new {
intercept /\Asay_([a-z]+)\Z/ do |method_name, matches, *arguments, &block|
"#{matches[1]}!"
end
}
end
```
Now you can say things:
```ruby
foo = Foo.new
foo.say_hello
#=> "hello!"
foo.say_bye
#=> "bye!"
```
That's it!
## More Information
- [Github repository](https://www.github.com/shioyama/method_found)
- [API documentation][docs]
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).