method_found 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87e6b7f548bcfc681da522938856c33fd8cb84b8
4
- data.tar.gz: 951ad82e7e12dc2e3b9d98919e72c15679014325
3
+ metadata.gz: b2e8e38c169b46157f6c1a94856b022b110efc13
4
+ data.tar.gz: 0c0b6468a1d9e23d1238379e4963fcf37e7e5e51
5
5
  SHA512:
6
- metadata.gz: 53cff1f4eb984fb62894dd02cbd3bdc899a5cb9e670f210098d850a00b0623513f341e66402f06b06853df76d3001b97c92cff82a018bbaadd6d8cf320f9f6fb
7
- data.tar.gz: e07d3e2b66b2c18281430a32585623105716d7a29059d1dc202f7947e465b42fcf4a12d27fd82ca4f6cd4ba915807628b4a9f1e76c3fa63e5062f51caa74d60f
6
+ metadata.gz: 664ef99573b8519bffd46a80a92183477a9d0e4c74dbffbfdba48d723ef1d90e8813b536947635706f66f05561ac22ffbffaa70f801912475deb6688127f98e6
7
+ data.tar.gz: f8dd6a6173cd3b73476ca500055e0b0d2b72de6d6f10f8a14266467dc8e227477a32a088edf4223fb4aa4ffb4d7bebf5a5a9e13ed2e70ad1b7a0f02cd6a5812b
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in method_found.gemspec
4
4
  gemspec
5
+
6
+ gem "pry-byebug"
data/README.md CHANGED
@@ -1,39 +1,35 @@
1
1
  # MethodFound
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/method_found`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Intercept `method_missing` and do something useful with it.
6
4
 
7
5
  ## Installation
8
6
 
9
- Add this line to your application's Gemfile:
7
+ Add to your Gemfile:
10
8
 
11
9
  ```ruby
12
- gem 'method_found'
10
+ gem 'method_found', '~> 0.1.0'
13
11
  ```
14
12
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install method_found
13
+ And bundle it.
22
14
 
23
15
  ## Usage
24
16
 
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/method_found. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
17
+ Include an instance of `MethodFound` with a regex to match and block which
18
+ takes the method name, regex matches, and arguments and does something with it:
36
19
 
20
+ ```ruby
21
+ class Foo
22
+ include(MethodFound.new(/\Asay_([a-z]+)/Z/) do |method_name, matches, *arguments|
23
+ "#{matches[0]}!"
24
+ end)
25
+ end
26
+
27
+ foo = Foo.new
28
+ foo.say_hello
29
+ #=> "hello!"
30
+ foo.say_bye
31
+ #=> "bye!"
32
+ ```
37
33
 
38
34
  ## License
39
35
 
@@ -0,0 +1,17 @@
1
+ module MethodFound
2
+ class Interceptor < Module
3
+ def initialize(regex, &intercept_block)
4
+ define_method :method_missing do |method_name, *arguments, &method_block|
5
+ if matches = regex.match(method_name)
6
+ instance_exec(method_name, matches, *arguments, &intercept_block)
7
+ else
8
+ super(method_name, *arguments, &method_block)
9
+ end
10
+ end
11
+
12
+ define_method :respond_to_missing? do |method_name, include_private = false|
13
+ (method_name =~ regex) || super(method_name, include_private)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module MethodFound
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/method_found.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require "method_found/version"
2
+ require "method_found/interceptor"
2
3
 
3
4
  module MethodFound
4
- # Your code goes here...
5
+ def self.new(*args, &block)
6
+ Interceptor.new(*args, &block)
7
+ end
5
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method_found
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg
@@ -70,6 +70,7 @@ files:
70
70
  - bin/console
71
71
  - bin/setup
72
72
  - lib/method_found.rb
73
+ - lib/method_found/interceptor.rb
73
74
  - lib/method_found/version.rb
74
75
  - method_found.gemspec
75
76
  homepage: https://github.com/shioyama/method_found