Class: FieldedArray

Inherits:
Object
  • Object
show all
Includes:
Fieldable
Defined in:
lib/arrayfields.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Fieldable

#fields, #fields=, #fieldset

Constructor Details

#initialize(fields = [], array = []) ⇒ FieldedArray

Returns a new instance of FieldedArray.



412
413
414
415
# File 'lib/arrayfields.rb', line 412

def initialize fields = [], array = []
  @a = array
  self.fields = fields
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



416
417
418
# File 'lib/arrayfields.rb', line 416

def method_missing(meth, *args, &block)
  @a.send(meth, *args, &block)
end

Class Method Details

.[](*pairs) ⇒ Object

Raises:

  • (ArgumentError)


401
402
403
404
405
406
407
408
409
410
# File 'lib/arrayfields.rb', line 401

def [](*pairs)
  pairs.flatten!
  raise ArgumentError, "argument must be key/val pairs" unless 
    (pairs.size % 2 == 0)
  fields, elements = [], []
  while((f = pairs.shift) and (e = pairs.shift)) 
    fields << f and elements << e
  end
  new fields, elements
end