Class: CGenerator::Template
- Inherits:
-
Accumulator
- Object
- Accumulator
- CGenerator::Template
- Defined in:
- lib/cgen/cgen.rb
Overview
All templates respond to #library and #file methods, which return the library or file object which contains the template. (The library itself does not respond to #file.) They also respond to #name and #parent.
Instance Attribute Summary
Attributes inherited from Accumulator
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name = "", parent = nil, &block) ⇒ Template
constructor
A new instance of Template.
Methods inherited from Accumulator
#accept?, #add, #add_one, #add_one_really, #inspect, #inspect_one, #output, #output_one, #separator, #to_s
Constructor Details
#initialize(name = "", parent = nil, &block) ⇒ Template
Returns a new instance of Template.
537 538 539 540 541 |
# File 'lib/cgen/cgen.rb', line 537 def initialize name = "", parent = nil, &block super instance_eval(&block) if block ## not very useful: users call an accumulator, rather than Template#new end |
Class Method Details
.accumulator(*names) ⇒ Object
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'lib/cgen/cgen.rb', line 543 def Template.accumulator(*names) kind = if block_given? then yield else Accumulator end for name in names module_eval %{ def #{name}(*items) #{name}!.add(*items) end def #{name}! @#{name} ||= #{kind}.new(:#{name}, self) end } unless Template.respond_to? name Template.inherit :@parent, name end end end |