attributes 3.2.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +50 -23
- data/README.tmpl +13 -8
- data/attributes-3.3.0.gem +0 -0
- data/lib/{attributes-3.2.0.rb → attributes-3.3.0.rb} +22 -22
- data/lib/attributes.rb +22 -22
- metadata +32 -24
data/README
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
NAME
|
2
|
-
|
3
2
|
attributes.rb
|
4
3
|
|
5
|
-
|
4
|
+
INSTALL
|
5
|
+
gem install attributes
|
6
6
|
|
7
|
+
URIS
|
7
8
|
http://rubyforge.org/projects/codeforpeople/
|
8
9
|
http://codeforpeople.com/lib/ruby
|
9
10
|
|
10
11
|
SYNOPSIS
|
11
|
-
|
12
|
-
attributes.rb
|
13
|
-
|
14
|
-
|
15
|
-
lines of code.
|
12
|
+
attributes.rb provides a set of attr_* like method with several user
|
13
|
+
friendly additions. attributes.rb is similar to the traits.rb package but
|
14
|
+
sacrifices a few features for simplicity of implementation: attributes.rb is
|
15
|
+
only 42 lines of code.
|
16
16
|
|
17
17
|
the implimentation of attributes.rb borrows many of the best ideas from the
|
18
18
|
metakoans.rb ruby quiz
|
@@ -21,6 +21,12 @@ SYNOPSIS
|
|
21
21
|
|
22
22
|
in particular the solutions of Christian Neukirchen and Florian Gross.
|
23
23
|
|
24
|
+
HISTORY
|
25
|
+
3.3.0
|
26
|
+
|
27
|
+
moved to an instance variable-less model using an module level closure for
|
28
|
+
the attributes list
|
29
|
+
|
24
30
|
SAMPLES
|
25
31
|
|
26
32
|
<========< samples/a.rb >========>
|
@@ -52,10 +58,9 @@ SAMPLES
|
|
52
58
|
|
53
59
|
~ > ruby samples/a.rb
|
54
60
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
./lib/attributes.rb:64: syntax error from samples/a.rb:5
|
61
|
+
42
|
62
|
+
"forty-two"
|
63
|
+
42
|
59
64
|
|
60
65
|
|
61
66
|
<========< samples/b.rb >========>
|
@@ -81,10 +86,8 @@ SAMPLES
|
|
81
86
|
|
82
87
|
~ > ruby samples/b.rb
|
83
88
|
|
84
|
-
|
85
|
-
|
86
|
-
^
|
87
|
-
./lib/attributes.rb:64: syntax error from samples/b.rb:6
|
89
|
+
42
|
90
|
+
42.0
|
88
91
|
|
89
92
|
|
90
93
|
<========< samples/c.rb >========>
|
@@ -106,10 +109,7 @@ SAMPLES
|
|
106
109
|
|
107
110
|
~ > ruby samples/c.rb
|
108
111
|
|
109
|
-
|
110
|
-
def attributes *a &b
|
111
|
-
^
|
112
|
-
./lib/attributes.rb:64: syntax error from samples/c.rb:4
|
112
|
+
42
|
113
113
|
|
114
114
|
|
115
115
|
<========< samples/d.rb >========>
|
@@ -153,8 +153,35 @@ SAMPLES
|
|
153
153
|
|
154
154
|
~ > ruby samples/d.rb
|
155
155
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
156
|
+
["x", "y", "z"]
|
157
|
+
{"x"=>0, "y"=>1, "z"=>2}
|
158
|
+
"forty-two"
|
159
|
+
|
160
|
+
|
161
|
+
<========< samples/e.rb >========>
|
162
|
+
|
163
|
+
~ > cat samples/e.rb
|
164
|
+
|
165
|
+
#
|
166
|
+
# my favourite element of attributes is that getters can also be setters.
|
167
|
+
# this allows incredibly clean looking code like
|
168
|
+
#
|
169
|
+
require 'attributes'
|
170
|
+
|
171
|
+
class Config
|
172
|
+
attributes %w( host port)
|
173
|
+
def initialize(&block) instance_eval &block end
|
174
|
+
end
|
175
|
+
|
176
|
+
conf = Config.new{
|
177
|
+
host 'codeforpeople.org'
|
178
|
+
|
179
|
+
port 80
|
180
|
+
}
|
181
|
+
|
182
|
+
p conf
|
183
|
+
|
184
|
+
~ > ruby samples/e.rb
|
185
|
+
|
186
|
+
#<Config:0x220b0 @port=80, @host="codeforpeople.org">
|
160
187
|
|
data/README.tmpl
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
NAME
|
2
|
-
|
3
2
|
attributes.rb
|
4
3
|
|
5
|
-
|
4
|
+
INSTALL
|
5
|
+
gem install attributes
|
6
6
|
|
7
|
+
URIS
|
7
8
|
http://rubyforge.org/projects/codeforpeople/
|
8
9
|
http://codeforpeople.com/lib/ruby
|
9
10
|
|
10
11
|
SYNOPSIS
|
11
|
-
|
12
|
-
attributes.rb
|
13
|
-
|
14
|
-
|
15
|
-
lines of code.
|
12
|
+
attributes.rb provides a set of attr_* like method with several user
|
13
|
+
friendly additions. attributes.rb is similar to the traits.rb package but
|
14
|
+
sacrifices a few features for simplicity of implementation: attributes.rb is
|
15
|
+
only 42 lines of code.
|
16
16
|
|
17
17
|
the implimentation of attributes.rb borrows many of the best ideas from the
|
18
18
|
metakoans.rb ruby quiz
|
@@ -21,6 +21,11 @@ SYNOPSIS
|
|
21
21
|
|
22
22
|
in particular the solutions of Christian Neukirchen and Florian Gross.
|
23
23
|
|
24
|
-
|
24
|
+
HISTORY
|
25
|
+
3.3.0
|
26
|
+
|
27
|
+
moved to an instance variable-less model using an module level closure for
|
28
|
+
the attributes list
|
25
29
|
|
30
|
+
SAMPLES
|
26
31
|
@samples
|
File without changes
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Attributes
|
2
|
-
VERSION = '3.
|
3
|
-
|
4
|
-
def version() VERSION end
|
2
|
+
VERSION = '3.3.0'
|
3
|
+
def self.version() VERSION end
|
5
4
|
|
6
5
|
def attributes *a, &b
|
7
6
|
unless a.empty?
|
@@ -13,10 +12,7 @@ module Attributes
|
|
13
12
|
|
14
13
|
names_and_defaults.each do |name, default|
|
15
14
|
init = b || lambda { default }
|
16
|
-
ivar = "@#{ name }"
|
17
|
-
getter = "#{ name }"
|
18
|
-
setter = "#{ name }="
|
19
|
-
query = "#{ name }?"
|
15
|
+
ivar, getter, setter, query = "@#{ name }", "#{ name }", "#{ name }=", "#{ name }?"
|
20
16
|
|
21
17
|
define_method(setter) do |value|
|
22
18
|
instance_variable_set ivar, value
|
@@ -27,9 +23,7 @@ module Attributes
|
|
27
23
|
send setter, value.shift
|
28
24
|
else
|
29
25
|
defined = instance_eval "defined? #{ ivar }"
|
30
|
-
unless defined
|
31
|
-
send setter, instance_eval(&init)
|
32
|
-
end
|
26
|
+
send setter, instance_eval(&init) unless defined
|
33
27
|
instance_variable_get ivar
|
34
28
|
end
|
35
29
|
end
|
@@ -40,29 +34,35 @@ module Attributes
|
|
40
34
|
attributes
|
41
35
|
end
|
42
36
|
else
|
43
|
-
|
37
|
+
begin
|
38
|
+
__attribute_list__
|
39
|
+
rescue NameError
|
40
|
+
singleton_class =
|
41
|
+
class << self
|
42
|
+
self
|
43
|
+
end
|
44
|
+
singleton_class.module_eval <<-code
|
45
|
+
attribute_list = []
|
46
|
+
define_method('attribute_list'){ attribute_list }
|
47
|
+
alias_method '__attribute_list__', 'attribute_list'
|
48
|
+
code
|
49
|
+
__attribute_list__
|
50
|
+
end
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
47
|
-
|
48
|
-
attributes *a, &b
|
49
|
-
end
|
54
|
+
%w( __attributes__ __attribute__ attribute ).each{|dst| alias_method dst, 'attributes'}
|
50
55
|
end
|
51
56
|
|
52
57
|
class Object
|
53
58
|
def attributes *a, &b
|
54
|
-
sc =
|
59
|
+
sc =
|
55
60
|
class << self
|
56
61
|
self
|
57
62
|
end
|
58
63
|
sc.attributes *a, &b
|
59
64
|
end
|
60
|
-
|
61
|
-
def attribute *a, &b
|
62
|
-
attributes *a, &b
|
63
|
-
end
|
65
|
+
%w( __attributes__ __attribute__ attribute ).each{|dst| alias_method dst, 'attributes'}
|
64
66
|
end
|
65
67
|
|
66
|
-
class Module
|
67
|
-
include Attributes
|
68
|
-
end
|
68
|
+
class Module; include Attributes; end
|
data/lib/attributes.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Attributes
|
2
|
-
VERSION = '3.
|
3
|
-
|
4
|
-
def version() VERSION end
|
2
|
+
VERSION = '3.3.0'
|
3
|
+
def self.version() VERSION end
|
5
4
|
|
6
5
|
def attributes *a, &b
|
7
6
|
unless a.empty?
|
@@ -13,10 +12,7 @@ module Attributes
|
|
13
12
|
|
14
13
|
names_and_defaults.each do |name, default|
|
15
14
|
init = b || lambda { default }
|
16
|
-
ivar = "@#{ name }"
|
17
|
-
getter = "#{ name }"
|
18
|
-
setter = "#{ name }="
|
19
|
-
query = "#{ name }?"
|
15
|
+
ivar, getter, setter, query = "@#{ name }", "#{ name }", "#{ name }=", "#{ name }?"
|
20
16
|
|
21
17
|
define_method(setter) do |value|
|
22
18
|
instance_variable_set ivar, value
|
@@ -27,9 +23,7 @@ module Attributes
|
|
27
23
|
send setter, value.shift
|
28
24
|
else
|
29
25
|
defined = instance_eval "defined? #{ ivar }"
|
30
|
-
unless defined
|
31
|
-
send setter, instance_eval(&init)
|
32
|
-
end
|
26
|
+
send setter, instance_eval(&init) unless defined
|
33
27
|
instance_variable_get ivar
|
34
28
|
end
|
35
29
|
end
|
@@ -40,29 +34,35 @@ module Attributes
|
|
40
34
|
attributes
|
41
35
|
end
|
42
36
|
else
|
43
|
-
|
37
|
+
begin
|
38
|
+
__attribute_list__
|
39
|
+
rescue NameError
|
40
|
+
singleton_class =
|
41
|
+
class << self
|
42
|
+
self
|
43
|
+
end
|
44
|
+
singleton_class.module_eval <<-code
|
45
|
+
attribute_list = []
|
46
|
+
define_method('attribute_list'){ attribute_list }
|
47
|
+
alias_method '__attribute_list__', 'attribute_list'
|
48
|
+
code
|
49
|
+
__attribute_list__
|
50
|
+
end
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
47
|
-
|
48
|
-
attributes *a, &b
|
49
|
-
end
|
54
|
+
%w( __attributes__ __attribute__ attribute ).each{|dst| alias_method dst, 'attributes'}
|
50
55
|
end
|
51
56
|
|
52
57
|
class Object
|
53
58
|
def attributes *a, &b
|
54
|
-
sc =
|
59
|
+
sc =
|
55
60
|
class << self
|
56
61
|
self
|
57
62
|
end
|
58
63
|
sc.attributes *a, &b
|
59
64
|
end
|
60
|
-
|
61
|
-
def attribute *a, &b
|
62
|
-
attributes *a, &b
|
63
|
-
end
|
65
|
+
%w( __attributes__ __attribute__ attribute ).each{|dst| alias_method dst, 'attributes'}
|
64
66
|
end
|
65
67
|
|
66
|
-
class Module
|
67
|
-
include Attributes
|
68
|
-
end
|
68
|
+
class Module; include Attributes; end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.2
|
3
3
|
specification_version: 1
|
4
4
|
name: attributes
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 3.
|
7
|
-
date:
|
6
|
+
version: 3.3.0
|
7
|
+
date: 2007-06-04 00:00:00 -06:00
|
8
8
|
summary: attributes
|
9
9
|
require_paths:
|
10
|
-
|
10
|
+
- lib
|
11
11
|
email: ara.t.howard@noaa.gov
|
12
12
|
homepage: http://codeforpeople.com/lib/ruby/attributes/
|
13
13
|
rubyforge_project:
|
@@ -18,35 +18,43 @@ bindir: bin
|
|
18
18
|
has_rdoc: false
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
20
|
requirements:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
version: 0.0.0
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
25
24
|
version:
|
26
25
|
platform: ruby
|
27
26
|
signing_key:
|
28
27
|
cert_chain:
|
28
|
+
post_install_message:
|
29
29
|
authors:
|
30
|
-
|
30
|
+
- Ara T. Howard
|
31
31
|
files:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
32
|
+
- attributes-3.3.0.gem
|
33
|
+
- gemspec.rb
|
34
|
+
- gen_readme.rb
|
35
|
+
- install.rb
|
36
|
+
- lib
|
37
|
+
- lib/attributes-3.3.0.rb
|
38
|
+
- lib/attributes.rb
|
39
|
+
- README
|
40
|
+
- README.tmpl
|
41
|
+
- samples
|
42
|
+
- samples/a.rb
|
43
|
+
- samples/b.rb
|
44
|
+
- samples/c.rb
|
45
|
+
- samples/d.rb
|
46
|
+
- samples/e.rb
|
46
47
|
test_files: []
|
48
|
+
|
47
49
|
rdoc_options: []
|
50
|
+
|
48
51
|
extra_rdoc_files: []
|
52
|
+
|
49
53
|
executables: []
|
54
|
+
|
50
55
|
extensions: []
|
56
|
+
|
51
57
|
requirements: []
|
52
|
-
|
58
|
+
|
59
|
+
dependencies: []
|
60
|
+
|