motion-define-method 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/lib/define-method/module_ext.rb +15 -10
- data/lib/define-method/version.rb +1 -1
- metadata +3 -3
data/Gemfile.lock
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
+
$define_method_blocks ||= {}
|
2
|
+
|
1
3
|
class Module
|
2
4
|
def define_method(name, *args, &blk)
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
@define_method_blocks[name] = args[0]
|
5
|
+
$define_method_blocks[self.to_s] ||= {}
|
6
|
+
if block_given?
|
7
|
+
$define_method_blocks[self.to_s][name] = lambda(&blk)
|
7
8
|
elsif
|
8
|
-
|
9
|
+
$define_method_blocks[self.to_s][name] = args[0]
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
@@ -14,16 +15,20 @@ class Object
|
|
14
15
|
attr_accessor :define_method_blocks
|
15
16
|
alias_method :original_module_method_missing, :method_missing
|
16
17
|
def method_missing(method, *args, &block)
|
17
|
-
self.class.
|
18
|
-
|
19
|
-
|
18
|
+
if $define_method_blocks[self.class.to_s] && $define_method_blocks[self.class.to_s].include?(method)
|
19
|
+
return $define_method_blocks[self.class.to_s][method].call(*args)
|
20
|
+
|
21
|
+
elsif self.respond_to?(:metaclass) && $define_method_blocks[self.metaclass.to_s] && $define_method_blocks[self.metaclass.to_s].include?(method)
|
22
|
+
return $define_method_blocks[self.metaclass.to_s][method].call(*args)
|
23
|
+
|
20
24
|
else
|
21
25
|
self.class.ancestors.each do |clazz|
|
22
|
-
if clazz.
|
23
|
-
return clazz.
|
26
|
+
if $define_method_blocks[clazz.to_s] && $define_method_blocks[clazz.to_s].include?(method)
|
27
|
+
return $define_method_blocks[clazz.to_s][method].call(*args)
|
24
28
|
end
|
25
29
|
end
|
26
30
|
return original_module_method_missing(method, *args)
|
31
|
+
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-define-method
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -75,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: '0'
|
76
76
|
segments:
|
77
77
|
- 0
|
78
|
-
hash:
|
78
|
+
hash: 1104225112934665263
|
79
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
80
|
none: false
|
81
81
|
requirements:
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
segments:
|
86
86
|
- 0
|
87
|
-
hash:
|
87
|
+
hash: 1104225112934665263
|
88
88
|
requirements: []
|
89
89
|
rubyforge_project:
|
90
90
|
rubygems_version: 1.8.24
|