jbr-enumerable-proxy 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +5 -0
  2. data/lib/enumerable_proxy.rb +31 -0
  3. metadata +75 -0
data/README ADDED
@@ -0,0 +1,5 @@
1
+ See http://www.jacobrothstein.com/entries/enumerable-proxy
2
+
3
+ and
4
+
5
+ http://www.jacobrothstein.com/entries/further-enumerable-proxy
@@ -0,0 +1,31 @@
1
+ module Enumerable
2
+ def proxy(method) Proxy.new method, self end
3
+
4
+ class Proxy
5
+ instance_methods.each { |m| undef_method m unless m =~ /^__/ }
6
+
7
+ def initialize(method, enumerable)
8
+ @method, @enumerable = method, enumerable
9
+ end
10
+
11
+ def method_missing(method, *args)
12
+ @enumerable.send(@method) {|a| a.send method, *args}
13
+ end
14
+ end
15
+ end
16
+
17
+ class Array
18
+ %w(each map select reject all?).each do |method|
19
+ aliased_target, punctuation = method.to_s.sub(/([?!])$/, ''), $1
20
+ with_proxy = "#{aliased_target}_with_proxy#{punctuation}"
21
+ without_proxy = with_proxy.sub "with", "without"
22
+
23
+ class_eval %{
24
+ def #{with_proxy}(&blk)
25
+ blk.nil? ? proxy(:#{method}) : #{without_proxy}(&blk)
26
+ end
27
+ alias_method :#{without_proxy}, :#{method}
28
+ alias_method :#{method}, :#{with_proxy}
29
+ }
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jbr-enumerable-proxy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jacob Rothstein
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-25 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mime-types
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "1.15"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: diff-lcs
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.2
34
+ version:
35
+ description: Enumerable::Proxy is a pattern for simple block-free ruby enumeration
36
+ email: jacob@stormweight.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README
43
+ files:
44
+ - lib/enumerable_proxy.rb
45
+ - README
46
+ has_rdoc: false
47
+ homepage: http://github.com/jbr/Enumerable--Proxy
48
+ licenses:
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --inline-source
52
+ - --charset=UTF-8
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.5
71
+ signing_key:
72
+ specification_version: 2
73
+ summary: Enumerable::Proxy is a pattern for simple block-free ruby enumeration
74
+ test_files: []
75
+