refining 0.0.5.2 → 0.0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/refining.rb +54 -43
  2. metadata +41 -28
@@ -11,63 +11,74 @@
11
11
  #++
12
12
 
13
13
  class Object
14
- def refine_singleton_method (meth, &block)
15
- return unless block
14
+ def refine_singleton_method (meth, options = {}, &block)
15
+ return unless block
16
16
 
17
- target = self
17
+ what = class << self
18
+ self
19
+ end
18
20
 
19
- (method(meth) rescue nil).tap {|old|
20
- old ||= proc {}
21
+ if options[:alias] || options[:prefix]
22
+ what.instance_eval {
23
+ alias_method options[:alias] || "#{options[:prefix]}_#{meth}", meth
24
+ define_method meth, &block
25
+ }
26
+ else
27
+ target = self
21
28
 
22
- what = class << target
23
- self
24
- end
29
+ (method(meth) rescue nil).tap {|old|
30
+ old ||= proc {}
25
31
 
26
- what.__send__ :define_method, meth do |*args, &blk|
27
- return if instance_variable_defined?(:@__refining_defined__) && [:method_added, :singleton_method_added].member?(meth)
28
-
29
- @__refining_defined__ = true
30
- what.__send__(:define_method, 'temporary method for refining', &block)
31
-
32
- target.__send__('temporary method for refining', old.is_a?(UnboundMethod) ? old.bind(self) : old, *args, &blk).tap {
33
- what.__send__(:undef_method, 'temporary method for refining') rescue nil
32
+ what.instance_eval {
33
+ define_method meth do |*args, &blk|
34
+ what.instance_eval {
35
+ define_method 'temporary method for refining', &block
34
36
 
35
- remove_instance_variable(:@__refining_defined__) rescue nil
36
- }
37
- end
38
- }
39
- end
37
+ target.__send__('temporary method for refining', old, *args, &blk).tap {
38
+ undef_method('temporary method for refining') rescue nil
39
+ }
40
+ }
41
+ end
42
+ }
43
+ }
44
+ end
45
+ end
40
46
  end
41
47
 
42
48
  class Module
43
- def refine_method (meth, &block)
44
- return unless block
49
+ def refine_method (meth, options = {}, &block)
50
+ return unless block
45
51
 
46
- (instance_method(meth) rescue nil).tap {|old|
47
- old ||= proc {}
52
+ if options[:alias] || options[:prefix]
53
+ instance_eval {
54
+ alias_method options[:alias] || "#{options[:prefix]}_#{meth}", meth
55
+ define_method meth, &block
56
+ }
57
+ else
58
+ (instance_method(meth) rescue nil).tap {|old|
59
+ old ||= proc {}
48
60
 
49
- define_method(meth) {|*args, &blk|
50
- return if instance_variable_defined?(:@__refining_defined__) && [:method_added, :singleton_method_added].member?(meth)
61
+ define_method meth do |*args, &blk|
62
+ target = self
63
+ what = class << target
64
+ self
65
+ end
51
66
 
52
- what = class << self
53
- self
54
- end
67
+ what.instance_eval {
68
+ define_method 'temporary method for refining', &block
55
69
 
56
- @__refining_defined__ = true
57
- what.__send__(:define_method, 'temporary method for refining', &block)
58
-
59
- __send__('temporary method for refining', old.is_a?(UnboundMethod) ? old.bind(self) : old, *args, &blk).tap {
60
- what.__send__(:undef_method, 'temporary method for refining') rescue nil
70
+ target.__send__('temporary method for refining', old.is_a?(UnboundMethod) ? old.bind(target) : old, *args, &blk).tap {
71
+ undef_method 'temporary method for refining' rescue nil
72
+ }
73
+ }
74
+ end
75
+ }
76
+ end
77
+ end
61
78
 
62
- remove_instance_variable(:@__refining_defined__) rescue nil
63
- }
64
- }
65
- }
66
- end
67
-
68
- alias refine_module_method refine_singleton_method
79
+ alias refine_module_method refine_singleton_method
69
80
  end
70
81
 
71
82
  class Class
72
- alias refine_class_method refine_singleton_method
83
+ alias refine_class_method refine_singleton_method
73
84
  end
metadata CHANGED
@@ -1,54 +1,67 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: refining
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5.3
4
5
  prerelease:
5
- version: 0.0.5.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - meh.
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-09-01 00:00:00 Z
14
- dependencies: []
15
-
12
+ date: 2011-11-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &18196600 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *18196600
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &18196100 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *18196100
16
36
  description:
17
37
  email: meh@paranoici.org
18
38
  executables: []
19
-
20
39
  extensions: []
21
-
22
40
  extra_rdoc_files: []
23
-
24
- files:
41
+ files:
25
42
  - lib/refining.rb
26
43
  homepage: http://github.com/meh/refining
27
44
  licenses: []
28
-
29
45
  post_install_message:
30
46
  rdoc_options: []
31
-
32
- require_paths:
47
+ require_paths:
33
48
  - lib
34
- required_ruby_version: !ruby/object:Gem::Requirement
49
+ required_ruby_version: !ruby/object:Gem::Requirement
35
50
  none: false
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: "0"
40
- required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
56
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
46
61
  requirements: []
47
-
48
62
  rubyforge_project:
49
- rubygems_version: 1.8.5
63
+ rubygems_version: 1.8.10
50
64
  signing_key:
51
65
  specification_version: 3
52
66
  summary: Easily refine methods
53
67
  test_files: []
54
-