Module: CGenerator::KeyAccumulator

Included in:
CFragment::StatementKeyAccumulator
Defined in:
lib/cgen/cgen.rb

Instance Method Summary collapse

Instance Method Details

#[](item) ⇒ Object



527
528
529
# File 'lib/cgen/cgen.rb', line 527

def [](item)
  @hash[item]
end

#add_one(item) ⇒ Object



498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/cgen/cgen.rb', line 498

def add_one item
## why not do this?
#    unless item.is_a? Hash
#      raise ArgumentError,
#        "Tried to add non-hash '#{item}' to KeyAccumulator."
#    end
  
  item = item.sort_by {|k,v| k.to_s} unless item.is_a?(Array)
  
  for key, value in item
    if not @hash.has_key? key
      super key
    end
    @hash[key] = value_filter(value)
  end
end

#initialize(*args) ⇒ Object



493
494
495
496
# File 'lib/cgen/cgen.rb', line 493

def initialize(*args)
  super
  @hash = {}  # @pile maintains ordered list of keys for @hash
end

#inspect_one(item) ⇒ Object



523
524
525
# File 'lib/cgen/cgen.rb', line 523

def inspect_one item
  @hash[item].inspect
end

#output_one(item) ⇒ Object



519
520
521
# File 'lib/cgen/cgen.rb', line 519

def output_one item
  super @hash[item]
end

#value_filter(value) ⇒ Object



515
516
517
# File 'lib/cgen/cgen.rb', line 515

def value_filter(value)
  value
end