Class: FieldedArray

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

Instance Attribute Summary

Attributes included from Fieldable

#fieldset

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Fieldable

#fields, #fields=

Constructor Details

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

Returns a new instance of FieldedArray.



327
328
329
330
# File 'lib/rq/arrayfields.rb', line 327

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



331
332
333
# File 'lib/rq/arrayfields.rb', line 331

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

Class Method Details

.[](*pairs) ⇒ Object

Raises:

  • (ArgumentError)


316
317
318
319
320
321
322
323
324
325
# File 'lib/rq/arrayfields.rb', line 316

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