shared 0.4.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +8 -0
- data/a.rb +12 -0
- data/lib/shared.rb +53 -42
- metadata +4 -3
data/README
CHANGED
@@ -12,6 +12,14 @@ URIS
|
|
12
12
|
http://codeforpeople.com/lib/ruby/
|
13
13
|
|
14
14
|
HISTORY
|
15
|
+
1.0.0
|
16
|
+
- add Share/Shared methods
|
17
|
+
- move from @@vars to closure based impl
|
18
|
+
|
19
|
+
0.4.5
|
20
|
+
- add Shared.for as 'shared' alias to rails' style const missing can
|
21
|
+
trigger lib load for a call. usage: Shared.for(:name){ ... }
|
22
|
+
|
15
23
|
0.4.3
|
16
24
|
- added version info
|
17
25
|
- move methods from Object to Kernel and made them private (thx Stefan
|
data/a.rb
ADDED
data/lib/shared.rb
CHANGED
@@ -1,63 +1,74 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
unless defined?(Shared)
|
2
|
+
module Shared
|
3
|
+
Shared::VERSION = '1.0.0' unless defined?(Shared::VERSION)
|
4
|
+
def version() Shared::VERSION end
|
4
5
|
|
5
|
-
|
6
|
+
Code = {}
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
def shared name, &block
|
9
|
+
key = key_for name
|
9
10
|
|
10
|
-
|
11
|
+
return Code[key] if block.nil?
|
11
12
|
|
12
|
-
|
13
|
+
m = (Code[key] || Module.new)
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
singleton_class(m) do
|
16
|
+
unless m.respond_to?(:blocks)
|
17
|
+
blocks = []
|
18
|
+
define_method(:blocks){ blocks }
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
blocks.each{|b| other.send(:module_eval, &b)}
|
22
|
-
end
|
20
|
+
define_method(:included) do |other|
|
21
|
+
blocks.each{|b| other.send(:module_eval, &b)}
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
define_method(:extend_object) do |other|
|
25
|
+
Shared.singleton_class(other) do
|
26
|
+
m.blocks.each{|b| module_eval &b}
|
27
|
+
end
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
31
|
+
|
32
|
+
m.blocks << block
|
33
|
+
|
34
|
+
Code[key] ||= m
|
30
35
|
end
|
36
|
+
|
37
|
+
alias_method 'share', 'shared'
|
38
|
+
alias_method 'for', 'shared'
|
39
|
+
alias_method '[]', 'shared'
|
31
40
|
|
32
|
-
|
41
|
+
def key_for name
|
42
|
+
name.to_s.strip.downcase
|
43
|
+
end
|
33
44
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
45
|
+
def singleton_class object, &block
|
46
|
+
singleton_class =
|
47
|
+
class << object
|
48
|
+
self
|
49
|
+
end
|
50
|
+
block ? singleton_class.module_eval(&block) : singleton_class
|
51
|
+
end
|
38
52
|
|
39
|
-
|
40
|
-
name.to_s.strip.downcase
|
53
|
+
extend self
|
41
54
|
end
|
42
55
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
block ? singleton_class.module_eval(&block) : singleton_class
|
49
|
-
end
|
56
|
+
module Kernel
|
57
|
+
private
|
58
|
+
def share(*a, &b)
|
59
|
+
Shared.share(*a, &b)
|
60
|
+
end
|
50
61
|
|
51
|
-
|
52
|
-
|
62
|
+
def Share(*a, &b)
|
63
|
+
Shared.share(*a, &b)
|
64
|
+
end
|
53
65
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
Shared.share *a, &b
|
58
|
-
end
|
66
|
+
def shared(*a, &b)
|
67
|
+
Shared.shared(*a, &b)
|
68
|
+
end
|
59
69
|
|
60
|
-
|
61
|
-
|
70
|
+
def Shared(*a, &b)
|
71
|
+
Shared.shared(*a, &b)
|
72
|
+
end
|
62
73
|
end
|
63
74
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shared
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ara T. Howard
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-02-05 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -31,6 +31,7 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
|
33
33
|
files:
|
34
|
+
- a.rb
|
34
35
|
- ann-shared-0.4.2.txt
|
35
36
|
- gemspec.rb
|
36
37
|
- gen_readme.rb
|
@@ -66,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
67
|
requirements: []
|
67
68
|
|
68
69
|
rubyforge_project: codeforpeople
|
69
|
-
rubygems_version: 1.
|
70
|
+
rubygems_version: 1.3.1
|
70
71
|
signing_key:
|
71
72
|
specification_version: 2
|
72
73
|
summary: shared
|