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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- motion-define-method (0.1.1)
4
+ motion-define-method (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,11 +1,12 @@
1
+ $define_method_blocks ||= {}
2
+
1
3
  class Module
2
4
  def define_method(name, *args, &blk)
3
- @define_method_blocks ||= {}
4
-
5
- if args.count > 0
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
- @define_method_blocks[name] = lambda(&blk)
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.define_method_blocks ||= {}
18
- if self.class.define_method_blocks && self.class.define_method_blocks.include?(method)
19
- return self.class.define_method_blocks[method].call(*args)
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.define_method_blocks && clazz.define_method_blocks.include?(method)
23
- return clazz.define_method_blocks[method].call(*args)
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
@@ -1,5 +1,5 @@
1
1
  module Motion
2
2
  module DefineMethod
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  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.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: -3361199952718360998
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: -3361199952718360998
87
+ hash: 1104225112934665263
88
88
  requirements: []
89
89
  rubyforge_project:
90
90
  rubygems_version: 1.8.24