Array instances are extened with two methods only: Fieldable#fields= and Fieldable#fields. only when Fieldable#fields= is called will the full set of ArrayFields methods auto-extend the Array instance. the Array class also has added a class generator when the fields are known apriori.
# File lib/arrayfields.rb, line 361 361: def self.[] *elements 362: array = new 363: array.replace elements 364: array 365: end
# File lib/arrayfields.rb, line 368 368: def fields *fields, &block 369: (( array = new(&block) )).fields = fields.map{|x| Enumerable === x ? x.to_a : x}.flatten 370: array 371: end
# File lib/arrayfields.rb, line 356 356: def initialize *a, &b 357: super 358: ensure 359: @fieldset = self.class.const_get :FIELDS 360: end
# File lib/arrayfields.rb, line 334 334: def struct *fields 335: fields = fields.flatten 336: Class.new(self) do 337: include ArrayFields 338: const_set :FIELDS, ArrayFields::FieldSet.new(fields) 339: fields.each do |field| 340: field = field.to_s 341: if field =~ /^[a-zA-Z_][a-zA-Z0-9_]*$/ 342: begin 343: module_eval def #{ field } *a a.size == 0 ? self['#{ field }'] : (self.#{ field } = a.shift) end def #{ field }= value self['#{ field }'] = value end 344: rescue SyntaxError 345: :by_ignoring_it 346: end 347: end 348: end 349: def initialize *a, &b 350: super 351: ensure 352: @fieldset = self.class.const_get :FIELDS 353: end 354: def self.[] *elements 355: array = new 356: array.replace elements 357: array 358: end 359: end 360: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.