Class: PseudoHash

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

Instance Attribute Summary

Attributes included from Fieldable

#fieldset

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Array

fields

Methods included from Fieldable

#fields, #fields=

Constructor Details

#initialize(keys = [], values = []) ⇒ PseudoHash

Returns a new instance of PseudoHash.



359
360
361
362
# File 'lib/rq/arrayfields.rb', line 359

def initialize keys = [], values = []
  self.fields = keys
  self.replace values
end

Class Method Details

.[](*pairs) ⇒ Object

Raises:

  • (ArgumentError)


348
349
350
351
352
353
354
355
356
357
# File 'lib/rq/arrayfields.rb', line 348

def [](*pairs)
  pairs.flatten!
  raise ArgumentError, "argument must be key/val pairs" unless 
    (pairs.size % 2 == 0 and pairs.size >= 2)
  keys, values = [], []
  while((k = pairs.shift) and (v = pairs.shift)) 
    keys << k and values << v
  end
  new keys, values
end

Instance Method Details

#to_yaml(opts = {}) ⇒ Object



363
364
365
366
367
368
369
# File 'lib/rq/arrayfields.rb', line 363

def to_yaml opts = {}
   YAML::quick_emit object_id, opts do |out|
     out.map taguri, to_yaml_style do |map|
       each_pair{|f,v| map.add f,v}
     end
   end
end