method_found 0.1.1 → 0.1.2

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: 54697c45ed4ce6071e6c36e15b8aa1a7ec0a2ace
4
- data.tar.gz: 366c25aaff318c8033e51ebff45c6415c5c32651
3
+ metadata.gz: 9de7a0b0880e53f1c96603d88fa416c025a4e29d
4
+ data.tar.gz: 4b65ed2fbf1926df69dc140341c677240fcc3a4d
5
5
  SHA512:
6
- metadata.gz: d78c7e39e4eb121df39f2f9f0b6c68c21cc0b1465bde81220b38bfa74b6d5d032e3f311fcfaf389d5eb40daccd81567d43b1c3c42f2ff749e435db1fc8a24ae1
7
- data.tar.gz: 9f3a8ef4238dcd2575dd5a55992835ac77033f5a4739db70f7b1624632e7ba4916d5cd4142aede903ed70d9cc9d342ff208d6161e494573c1b4714dfff10c3c2
6
+ metadata.gz: 0ad77664bf164a317b348a0af8822ec3532b2b688909fb216635abf7dacba6b70a185ee8cf8b53025972969ff7e96e42f1babd4a999d143a22700d1ca62b3f32
7
+ data.tar.gz: d35e820982307478a88e09ccf0b7c2c35725123f429d9795466c3b7451a51e278e395c73f0b0710e2c8d38f81797da7653503da5d090efd9796f454bb4cc0c2e
data/README.md CHANGED
@@ -13,7 +13,7 @@ Intercept `method_missing` and do something useful with it.
13
13
  Add to your Gemfile:
14
14
 
15
15
  ```ruby
16
- gem 'method_found', '~> 0.1.1'
16
+ gem 'method_found', '~> 0.1.2'
17
17
  ```
18
18
 
19
19
  And bundle it.
@@ -1,6 +1,13 @@
1
1
  module MethodFound
2
2
  class Interceptor < Module
3
- def initialize(regex, &intercept_block)
3
+ attr_reader :regex
4
+
5
+ def initialize(regex = nil, &intercept_block)
6
+ define_method_missing(regex, &intercept_block) unless regex.nil?
7
+ end
8
+
9
+ def define_method_missing(regex, &intercept_block)
10
+ @regex = regex
4
11
  define_method :method_missing do |method_name, *arguments, &method_block|
5
12
  if matches = regex.match(method_name)
6
13
  instance_exec(method_name, matches, *arguments, &intercept_block)
@@ -12,12 +19,12 @@ module MethodFound
12
19
  define_method :respond_to_missing? do |method_name, include_private = false|
13
20
  (method_name =~ regex) || super(method_name, include_private)
14
21
  end
22
+ end
15
23
 
16
- define_method :inspect do
17
- klass = self.class
18
- name = klass.name || klass.inspect
19
- "#<#{name}: #{regex.inspect}>"
20
- end
24
+ def inspect
25
+ klass = self.class
26
+ name = klass.name || klass.inspect
27
+ "#<#{name}: #{regex.inspect}>"
21
28
  end
22
29
  end
23
30
  end
@@ -1,3 +1,3 @@
1
1
  module MethodFound
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method_found
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-17 00:00:00.000000000 Z
11
+ date: 2017-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler