generate_method 0.0.1 → 1.0.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: e1aecfbdbc29d8cf9e86453a1a39971ecd6411ae
4
- data.tar.gz: 861f1c8d360a396f8eceb66536d227929843ce2a
3
+ metadata.gz: 4f3ac34096274543969e535344fd20e166b9a98d
4
+ data.tar.gz: 6956afd6f173fbf24c19e3f460675a5f38645181
5
5
  SHA512:
6
- metadata.gz: 424546393cb2758fba26e81e4ca3cca9341d0f6d146de388a258194fadcb0a18d38b89c777d8978392c9dbcc8f2df0b34b4bc2e0a773368377a085d7f9640407
7
- data.tar.gz: c807adb7103e542da8efa14af06cbe4414b27b3e758108b1d1b583ae64791198f40b338fa8d8e1bfefb5861279fde50b6b60354dc8c5cf2f1f33d55ccfe87c68
6
+ metadata.gz: c98c03142d6b79445b9fc37b7f18a4496fa6502b004c80c1ef6b366d81bdcbe99b24b0739e998c249f19a68c0f25e3c43dba0c4169c12b4641a32a344eff4fc6
7
+ data.tar.gz: 54712a7a5113ba20af0cc9bd4ee3e6aa1e4a4dfd0e535fe62483843c394d1b9b87b567210d9cabadee76db9ddcfeaf332ef43c2975144afdbe90b72854165a5d
data/README.md CHANGED
@@ -58,6 +58,9 @@ class Module
58
58
  end
59
59
  ```
60
60
 
61
+ To generate class method (singleton methods) you can use the equivalent
62
+ `generate_singleton_method` and `generate_singleton_methods`.
63
+
61
64
  By using one of the above syntax, a few problems will be solved:
62
65
 
63
66
  ### Ancestors stack
@@ -85,7 +88,7 @@ instance.x
85
88
  You can add `overrider: <overrider_name>` option to the `generate_method` call. This will
86
89
  cause existing methods in the class to be aliased into
87
90
  `<method_name>_without_<overrider_name>` (pushing ?/!,= to the end of the
88
- method name). That way you can easily call the overriden method in your
91
+ method name). That way you can easily call the overridden method in your
89
92
  generated method.
90
93
 
91
94
  ```ruby
@@ -3,23 +3,37 @@ require "generate_method/version"
3
3
  module GenerateMethod
4
4
  module Generator
5
5
  def generate_method(method_name, overrider: nil, &block)
6
+ include generate_method_module(method_name, overrider: overrider, &block)
7
+ end
8
+ def generate_singleton_method(method_name, overrider: nil, &block)
9
+ extend generate_method_module(method_name, overrider: overrider, &block)
10
+ end
11
+
12
+ def generate_methods(overrider: nil, &block)
13
+ include generate_block_module(overrider: overrider, &block)
14
+ end
15
+ def generate_singleton_methods(overrider: nil, &block)
16
+ extend generate_block_module(overrider: overrider, &block)
17
+ end
18
+
19
+ private
20
+
21
+ def generate_method_module(method_name, overrider: nil, &block)
6
22
  m = Module.new do
7
23
  define_method(method_name, &block)
8
24
  end
9
25
  alias_generated_method(method_name, overrider: overrider, m: m)
10
- include m
26
+ m
11
27
  end
12
28
 
13
- def generate_methods(overrider: nil, &block)
29
+ def generate_block_module(overrider: nil, &block)
14
30
  m = Module.new(&block)
15
31
  m.instance_methods.each do |method_name|
16
32
  alias_generated_method(method_name, overrider: overrider, m: m)
17
33
  end
18
- include m
34
+ m
19
35
  end
20
36
 
21
- private
22
-
23
37
  def alias_generated_method(method_name, overrider: nil, m: nil)
24
38
  return if overrider.nil?
25
39
 
@@ -1,3 +1,3 @@
1
1
  module GenerateMethod
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: generate_method
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oded Niv