arrayfields 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +33 -0
- data/README.tmpl +3 -0
- data/lib/{arrayfields-4.0.0.rb → arrayfields-4.1.0.rb} +25 -2
- data/lib/arrayfields.rb +25 -2
- data/sample/e.rb +15 -0
- metadata +4 -3
data/README
CHANGED
@@ -238,10 +238,43 @@ SAMPLES
|
|
238
238
|
[[:key, :value], [:a, :b]]
|
239
239
|
|
240
240
|
|
241
|
+
<========< sample/e.rb >========>
|
242
|
+
|
243
|
+
~ > cat sample/e.rb
|
244
|
+
|
245
|
+
require 'arrayfields'
|
246
|
+
|
247
|
+
Entry = Array.struct :path, :stat
|
248
|
+
|
249
|
+
entry = Entry[ File.basename(__FILE__), File.stat(__FILE__) ]
|
250
|
+
p entry[:path] #=> "e.rb"
|
251
|
+
p entry.path #=> "e.rb"
|
252
|
+
|
253
|
+
entry.path = 'foo'
|
254
|
+
p entry[:path] #=> "foo"
|
255
|
+
p entry.path #=> "foo"
|
256
|
+
|
257
|
+
entry.path 'bar' # getter acts as setter without args
|
258
|
+
p entry['path'] #=> "bar"
|
259
|
+
p entry.path #=> "bar"
|
260
|
+
|
261
|
+
~ > ruby sample/e.rb
|
262
|
+
|
263
|
+
"e.rb"
|
264
|
+
"e.rb"
|
265
|
+
"foo"
|
266
|
+
"foo"
|
267
|
+
"bar"
|
268
|
+
"bar"
|
269
|
+
|
270
|
+
|
241
271
|
AUTHOR
|
242
272
|
ara.t.howard@gmail.com
|
243
273
|
|
244
274
|
HISTORY
|
275
|
+
4.1.0:
|
276
|
+
- improved Array.struct method, see sample/e.rb
|
277
|
+
|
245
278
|
4.0.0:
|
246
279
|
- added Arrayfields.new(*arbitrary_evenly_numbered_list_of_objects)
|
247
280
|
- added #to_pairs and #pairs
|
data/README.tmpl
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Array#fields= is called
|
6
6
|
#
|
7
7
|
module ArrayFields
|
8
|
-
self::VERSION = '4.
|
8
|
+
self::VERSION = '4.1.0' unless defined? self::VERSION
|
9
9
|
def self.version() VERSION end
|
10
10
|
#
|
11
11
|
# multiton cache of fields - wraps fields and fieldpos map to save memory
|
@@ -317,14 +317,37 @@
|
|
317
317
|
|
318
318
|
class << self
|
319
319
|
def struct *fields
|
320
|
+
fields = fields.flatten
|
320
321
|
Class.new(self) do
|
321
|
-
const_set :FIELDS, ArrayFields::FieldSet.new(fields.flatten)
|
322
322
|
include ArrayFields
|
323
|
+
const_set :FIELDS, ArrayFields::FieldSet.new(fields)
|
324
|
+
fields.each do |field|
|
325
|
+
field = field.to_s
|
326
|
+
if field =~ %r/^[a-zA-Z_][a-zA-Z0-9_]*$/
|
327
|
+
begin
|
328
|
+
module_eval <<-code
|
329
|
+
def #{ field } *a
|
330
|
+
a.size == 0 ? self['#{ field }'] : (self.#{ field } = a.shift)
|
331
|
+
end
|
332
|
+
def #{ field }= value
|
333
|
+
self['#{ field }'] = value
|
334
|
+
end
|
335
|
+
code
|
336
|
+
rescue SyntaxError
|
337
|
+
:by_ignoring_it
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
323
341
|
def initialize *a, &b
|
324
342
|
super
|
325
343
|
ensure
|
326
344
|
@fieldset = self.class.const_get :FIELDS
|
327
345
|
end
|
346
|
+
def self.[] *elements
|
347
|
+
array = new
|
348
|
+
array.replace elements
|
349
|
+
array
|
350
|
+
end
|
328
351
|
end
|
329
352
|
end
|
330
353
|
def fields *fields, &block
|
data/lib/arrayfields.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Array#fields= is called
|
6
6
|
#
|
7
7
|
module ArrayFields
|
8
|
-
self::VERSION = '4.
|
8
|
+
self::VERSION = '4.1.0' unless defined? self::VERSION
|
9
9
|
def self.version() VERSION end
|
10
10
|
#
|
11
11
|
# multiton cache of fields - wraps fields and fieldpos map to save memory
|
@@ -317,14 +317,37 @@
|
|
317
317
|
|
318
318
|
class << self
|
319
319
|
def struct *fields
|
320
|
+
fields = fields.flatten
|
320
321
|
Class.new(self) do
|
321
|
-
const_set :FIELDS, ArrayFields::FieldSet.new(fields.flatten)
|
322
322
|
include ArrayFields
|
323
|
+
const_set :FIELDS, ArrayFields::FieldSet.new(fields)
|
324
|
+
fields.each do |field|
|
325
|
+
field = field.to_s
|
326
|
+
if field =~ %r/^[a-zA-Z_][a-zA-Z0-9_]*$/
|
327
|
+
begin
|
328
|
+
module_eval <<-code
|
329
|
+
def #{ field } *a
|
330
|
+
a.size == 0 ? self['#{ field }'] : (self.#{ field } = a.shift)
|
331
|
+
end
|
332
|
+
def #{ field }= value
|
333
|
+
self['#{ field }'] = value
|
334
|
+
end
|
335
|
+
code
|
336
|
+
rescue SyntaxError
|
337
|
+
:by_ignoring_it
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
323
341
|
def initialize *a, &b
|
324
342
|
super
|
325
343
|
ensure
|
326
344
|
@fieldset = self.class.const_get :FIELDS
|
327
345
|
end
|
346
|
+
def self.[] *elements
|
347
|
+
array = new
|
348
|
+
array.replace elements
|
349
|
+
array
|
350
|
+
end
|
328
351
|
end
|
329
352
|
end
|
330
353
|
def fields *fields, &block
|
data/sample/e.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'arrayfields'
|
2
|
+
|
3
|
+
Entry = Array.struct :path, :stat
|
4
|
+
|
5
|
+
entry = Entry[ File.basename(__FILE__), File.stat(__FILE__) ]
|
6
|
+
p entry[:path] #=> "e.rb"
|
7
|
+
p entry.path #=> "e.rb"
|
8
|
+
|
9
|
+
entry.path = 'foo'
|
10
|
+
p entry[:path] #=> "foo"
|
11
|
+
p entry.path #=> "foo"
|
12
|
+
|
13
|
+
entry.path 'bar' # getter acts as setter without args
|
14
|
+
p entry['path'] #=> "bar"
|
15
|
+
p entry.path #=> "bar"
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: arrayfields
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 4.
|
7
|
-
date: 2007-09-
|
6
|
+
version: 4.1.0
|
7
|
+
date: 2007-09-14 00:00:00 -06:00
|
8
8
|
summary: arrayfields
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -33,7 +33,7 @@ files:
|
|
33
33
|
- gen_readme.rb
|
34
34
|
- install.rb
|
35
35
|
- lib
|
36
|
-
- lib/arrayfields-4.
|
36
|
+
- lib/arrayfields-4.1.0.rb
|
37
37
|
- lib/arrayfields.rb
|
38
38
|
- README
|
39
39
|
- README.tmpl
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- sample/b.rb
|
43
43
|
- sample/c.rb
|
44
44
|
- sample/d.rb
|
45
|
+
- sample/e.rb
|
45
46
|
- test
|
46
47
|
- test/arrayfields.rb
|
47
48
|
- test/memtest.rb
|