monkey-lib 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/monkey/ext.rb CHANGED
@@ -18,7 +18,6 @@ module Monkey
18
18
  klass.send :include, self
19
19
  self::ClassMethods.extend ClassDsl
20
20
  self::ClassMethods.core_class core_class
21
- klass.extend self::ClassMethods
22
21
  @core_class.class_eval <<-EOS
23
22
  def method_missing(meth, *args, &blk)
24
23
  return super if Monkey::Backend.setup?
@@ -26,10 +25,21 @@ module Monkey
26
25
  __send__(meth, *args, &blk)
27
26
  end
28
27
  EOS
28
+ unless klass.is_a? Class
29
+ ObjectSpace.each_object(Module) do |mod|
30
+ next unless mod.ancestors.include? klass and not mod.ancestors.include? self
31
+ mod.send :include, klass
32
+ end
33
+ end
29
34
  end
30
35
  return @core_class
31
36
  end
32
37
 
38
+ def included(klass)
39
+ klass.extend self::ClassMethods
40
+ super
41
+ end
42
+
33
43
  def rename_core_method(old_name, new_name)
34
44
  core_class.send :undef_method, alias_core_method(old_name, new_name)
35
45
  end
@@ -0,0 +1,20 @@
1
+ module Monkey
2
+ module Ext
3
+ module Enumerable
4
+ def construct(obj)
5
+ enum_for :construct, obj unless block_given? or !respond_to? :enum_for
6
+ inject(obj) { |a,v| a.tap { yield(a, v) } }
7
+ end
8
+
9
+ def construct_hash(default = {})
10
+ enum_for :construct_hash unless block_given? or !respond_to? :enum_for
11
+ construct(default.to_hash.dup) do |h,v|
12
+ result = yield(v)
13
+ result = [result, nil] unless result.is_a? Enumerable
14
+ result = [result] unless result.respond_to? :to_ary
15
+ h.merge! Hash[*result]
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,5 @@
1
+ require "pathname"
2
+
1
3
  module Monkey
2
4
  module Ext
3
5
  module Pathname
@@ -20,4 +22,4 @@ module Monkey
20
22
 
21
23
  end
22
24
  end
23
- end
25
+ end
@@ -0,0 +1,28 @@
1
+ require __FILE__.sub(%r{monkey/.*$}, "spec_helper")
2
+
3
+ describe Monkey::Ext::Enumerable do
4
+ describe :construct do
5
+ it "always returns the initial object" do
6
+ obj = Object.new
7
+ (1..100).construct(obj) { "not obj" }.should == obj
8
+ end
9
+
10
+ it "allows modifying that object" do
11
+ ("a".."c").construct("result: ") { |a,v| a << v }.should == "result: abc"
12
+ end
13
+ end
14
+
15
+ describe :construct_hash do
16
+ it "constructs a hash from given hashes" do
17
+ ("a".."b").construct_hash { |v| { v => v } }.should == { "a" => "a", "b" => "b" }
18
+ end
19
+
20
+ it "constructs a hash from given arrays" do
21
+ ("a".."b").construct_hash { |v| [v, v] }.should == { "a" => "a", "b" => "b" }
22
+ end
23
+
24
+ it "takes an initial hash" do
25
+ ["a"].construct_hash("b" => "b") { |v| [v, v] }.should == { "a" => "a", "b" => "b" }
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monkey-lib
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 11
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 4
8
- - 1
9
- version: 0.4.1
9
+ - 2
10
+ version: 0.4.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Konstantin Haase
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-16 00:00:00 +02:00
18
+ date: 2010-05-31 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: backports
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -50,6 +53,7 @@ extra_rdoc_files:
50
53
  - lib/monkey/backend.rb
51
54
  - lib/monkey/engine.rb
52
55
  - lib/monkey/ext/array.rb
56
+ - lib/monkey/ext/enumerable.rb
53
57
  - lib/monkey/ext/file.rb
54
58
  - lib/monkey/ext/module.rb
55
59
  - lib/monkey/ext/object.rb
@@ -76,6 +80,7 @@ files:
76
80
  - lib/monkey/backend.rb
77
81
  - lib/monkey/engine.rb
78
82
  - lib/monkey/ext/array.rb
83
+ - lib/monkey/ext/enumerable.rb
79
84
  - lib/monkey/ext/file.rb
80
85
  - lib/monkey/ext/module.rb
81
86
  - lib/monkey/ext/object.rb
@@ -89,6 +94,7 @@ files:
89
94
  - spec/monkey/backend_spec.rb
90
95
  - spec/monkey/engine_spec.rb
91
96
  - spec/monkey/ext/array_spec.rb
97
+ - spec/monkey/ext/enumerable_spec.rb
92
98
  - spec/monkey/ext/module_spec.rb
93
99
  - spec/monkey/ext/object_spec.rb
94
100
  - spec/monkey/ext/pathname_spec.rb
@@ -106,23 +112,27 @@ rdoc_options: []
106
112
  require_paths:
107
113
  - lib
108
114
  required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
109
116
  requirements:
110
117
  - - ">="
111
118
  - !ruby/object:Gem::Version
119
+ hash: 3
112
120
  segments:
113
121
  - 0
114
122
  version: "0"
115
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
116
125
  requirements:
117
126
  - - ">="
118
127
  - !ruby/object:Gem::Version
128
+ hash: 3
119
129
  segments:
120
130
  - 0
121
131
  version: "0"
122
132
  requirements: []
123
133
 
124
134
  rubyforge_project:
125
- rubygems_version: 1.3.6
135
+ rubygems_version: 1.3.7
126
136
  signing_key:
127
137
  specification_version: 3
128
138
  summary: Making ruby extension frameworks pluggable.