refining 0.0.1

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.
Files changed (2) hide show
  1. data/lib/refining.rb +45 -0
  2. metadata +54 -0
data/lib/refining.rb ADDED
@@ -0,0 +1,45 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
6
+ #
7
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
8
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
9
+ #
10
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
11
+ #++
12
+
13
+ class Object
14
+ def refine_method (meth, &block)
15
+ return unless block_given?
16
+
17
+ old = self.method(meth) rescue Proc.new {}
18
+
19
+ define_singleton_method(meth) {|*args|
20
+ self.instance_exec(old, *args, &block)
21
+ }
22
+ end
23
+ end
24
+
25
+ class Class
26
+ def refine_method (meth, &block)
27
+ return unless block_given?
28
+
29
+ old = self.instance_method(meth) rescue Proc.new {}
30
+
31
+ define_method(meth) {|*args|
32
+ self.instance_exec((old.is_a?(Proc) ? old : old.bind(self)), *args, &block)
33
+ }
34
+ end
35
+
36
+ def refine_class_method (meth)
37
+ return unless block_given?
38
+
39
+ old = self.method(meth) rescue Proc.new {}
40
+
41
+ define_singleton_method(meth) {|*args|
42
+ yield old, *args
43
+ }
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refining
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - meh.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-13 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description:
17
+ email: meh@paranoici.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/refining.rb
26
+ homepage: http://github.com/meh/refining
27
+ licenses: []
28
+
29
+ post_install_message:
30
+ rdoc_options: []
31
+
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ requirements: []
47
+
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.5
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Easily refine methods
53
+ test_files: []
54
+