Class: PseudoHash
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Array
fields, struct
Methods included from Fieldable
#fields, #fields=, #fieldset
Constructor Details
#initialize(keys = [], values = []) ⇒ PseudoHash
Returns a new instance of PseudoHash.
444
445
446
447
|
# File 'lib/arrayfields.rb', line 444
def initialize keys = [], values = []
self.fields = keys
self.replace values
end
|
Class Method Details
.[](*pairs) ⇒ Object
433
434
435
436
437
438
439
440
441
442
|
# File 'lib/arrayfields.rb', line 433
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
448
449
450
451
452
453
454
|
# File 'lib/arrayfields.rb', line 448
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
|