attributes 3.0.1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +23 -9
- data/lib/{attributes-3.0.1.rb → attributes-3.2.0.rb} +19 -1
- data/lib/attributes.rb +19 -1
- data/samples/a.rb +7 -0
- data/samples/c.rb +0 -1
- data/samples/e.rb +18 -0
- metadata +4 -4
- data/attributes-3.0.0.gem +0 -0
data/README
CHANGED
@@ -42,11 +42,20 @@ SAMPLES
|
|
42
42
|
c.a = 42 # setter
|
43
43
|
p c.a # getter
|
44
44
|
p 'forty-two' if c.a? # query
|
45
|
+
|
46
|
+
#
|
47
|
+
# also not that attribute(s) works as well for objects as classes
|
48
|
+
#
|
49
|
+
o = Object.new
|
50
|
+
o.attribute 'answer' => 42
|
51
|
+
p o.answer
|
45
52
|
|
46
53
|
~ > ruby samples/a.rb
|
47
54
|
|
48
|
-
|
49
|
-
|
55
|
+
samples/a.rb:5:in `require': ./lib/attributes.rb:53: syntax error (SyntaxError)
|
56
|
+
def attributes *a &b
|
57
|
+
^
|
58
|
+
./lib/attributes.rb:64: syntax error from samples/a.rb:5
|
50
59
|
|
51
60
|
|
52
61
|
<========< samples/b.rb >========>
|
@@ -72,8 +81,10 @@ SAMPLES
|
|
72
81
|
|
73
82
|
~ > ruby samples/b.rb
|
74
83
|
|
75
|
-
|
76
|
-
|
84
|
+
samples/b.rb:6:in `require': ./lib/attributes.rb:53: syntax error (SyntaxError)
|
85
|
+
def attributes *a &b
|
86
|
+
^
|
87
|
+
./lib/attributes.rb:64: syntax error from samples/b.rb:6
|
77
88
|
|
78
89
|
|
79
90
|
<========< samples/c.rb >========>
|
@@ -92,11 +103,13 @@ SAMPLES
|
|
92
103
|
c = C.new
|
93
104
|
c.x = c.y + c.z
|
94
105
|
p c.x
|
95
|
-
|
96
106
|
|
97
107
|
~ > ruby samples/c.rb
|
98
108
|
|
99
|
-
|
109
|
+
samples/c.rb:4:in `require': ./lib/attributes.rb:53: syntax error (SyntaxError)
|
110
|
+
def attributes *a &b
|
111
|
+
^
|
112
|
+
./lib/attributes.rb:64: syntax error from samples/c.rb:4
|
100
113
|
|
101
114
|
|
102
115
|
<========< samples/d.rb >========>
|
@@ -140,7 +153,8 @@ SAMPLES
|
|
140
153
|
|
141
154
|
~ > ruby samples/d.rb
|
142
155
|
|
143
|
-
|
144
|
-
|
145
|
-
|
156
|
+
samples/d.rb:7:in `require': ./lib/attributes.rb:53: syntax error (SyntaxError)
|
157
|
+
def attributes *a &b
|
158
|
+
^
|
159
|
+
./lib/attributes.rb:64: syntax error from samples/d.rb:7
|
146
160
|
|
@@ -1,5 +1,8 @@
|
|
1
1
|
module Attributes
|
2
|
-
VERSION = '3.0
|
2
|
+
VERSION = '3.2.0'
|
3
|
+
|
4
|
+
def version() VERSION end
|
5
|
+
|
3
6
|
def attributes *a, &b
|
4
7
|
unless a.empty?
|
5
8
|
hashes, names = a.partition{|x| Hash === x}
|
@@ -40,6 +43,21 @@ module Attributes
|
|
40
43
|
@attributes ||= []
|
41
44
|
end
|
42
45
|
end
|
46
|
+
|
47
|
+
def attribute *a, &b
|
48
|
+
attributes *a, &b
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Object
|
53
|
+
def attributes *a, &b
|
54
|
+
sc =
|
55
|
+
class << self
|
56
|
+
self
|
57
|
+
end
|
58
|
+
sc.attributes *a, &b
|
59
|
+
end
|
60
|
+
|
43
61
|
def attribute *a, &b
|
44
62
|
attributes *a, &b
|
45
63
|
end
|
data/lib/attributes.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Attributes
|
2
|
-
VERSION = '3.0
|
2
|
+
VERSION = '3.2.0'
|
3
|
+
|
4
|
+
def version() VERSION end
|
5
|
+
|
3
6
|
def attributes *a, &b
|
4
7
|
unless a.empty?
|
5
8
|
hashes, names = a.partition{|x| Hash === x}
|
@@ -40,6 +43,21 @@ module Attributes
|
|
40
43
|
@attributes ||= []
|
41
44
|
end
|
42
45
|
end
|
46
|
+
|
47
|
+
def attribute *a, &b
|
48
|
+
attributes *a, &b
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Object
|
53
|
+
def attributes *a, &b
|
54
|
+
sc =
|
55
|
+
class << self
|
56
|
+
self
|
57
|
+
end
|
58
|
+
sc.attributes *a, &b
|
59
|
+
end
|
60
|
+
|
43
61
|
def attribute *a, &b
|
44
62
|
attributes *a, &b
|
45
63
|
end
|
data/samples/a.rb
CHANGED
data/samples/c.rb
CHANGED
data/samples/e.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# my favourite element of attributes is that getters can also be setters.
|
3
|
+
# this allows incredibly clean looking code like
|
4
|
+
#
|
5
|
+
require 'attributes'
|
6
|
+
|
7
|
+
class Config
|
8
|
+
attributes %w( host port)
|
9
|
+
def initialize(&block) instance_eval &block end
|
10
|
+
end
|
11
|
+
|
12
|
+
conf = Config.new{
|
13
|
+
host 'codeforpeople.org'
|
14
|
+
|
15
|
+
port 80
|
16
|
+
}
|
17
|
+
|
18
|
+
p conf
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: attributes
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 3.0
|
7
|
-
date: 2006-
|
6
|
+
version: 3.2.0
|
7
|
+
date: 2006-10-16 00:00:00.000000 -06:00
|
8
8
|
summary: attributes
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -36,13 +36,13 @@ files:
|
|
36
36
|
- gen_readme.rb
|
37
37
|
- README.tmpl
|
38
38
|
- README
|
39
|
-
- attributes-3.0.0.gem
|
40
39
|
- lib/attributes.rb
|
41
|
-
- lib/attributes-3.0.
|
40
|
+
- lib/attributes-3.2.0.rb
|
42
41
|
- samples/a.rb
|
43
42
|
- samples/b.rb
|
44
43
|
- samples/c.rb
|
45
44
|
- samples/d.rb
|
45
|
+
- samples/e.rb
|
46
46
|
test_files: []
|
47
47
|
rdoc_options: []
|
48
48
|
extra_rdoc_files: []
|
data/attributes-3.0.0.gem
DELETED
Binary file
|