Class: Amrita2::Core::CodeGenerator::CGModule
- Defined in:
- lib/amrita2/template.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#constants ⇒ Object
readonly
Returns the value of attribute constants.
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #define_constant(const_def) ⇒ Object
- #define_method(vars, &block) ⇒ Object
- #end_of_module(cg) ⇒ Object
-
#initialize(name) ⇒ CGModule
constructor
A new instance of CGModule.
Constructor Details
#initialize(name) ⇒ CGModule
Returns a new instance of CGModule.
694 695 696 697 698 |
# File 'lib/amrita2/template.rb', line 694 def initialize(name) @name = name @constants = [] @methods = [] end |
Instance Attribute Details
#constants ⇒ Object (readonly)
Returns the value of attribute constants.
691 692 693 |
# File 'lib/amrita2/template.rb', line 691 def constants @constants end |
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
692 693 694 |
# File 'lib/amrita2/template.rb', line 692 def methods @methods end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
690 691 692 |
# File 'lib/amrita2/template.rb', line 690 def name @name end |
Instance Method Details
#define_constant(const_def) ⇒ Object
700 701 702 703 704 705 706 707 708 709 710 711 712 713 |
# File 'lib/amrita2/template.rb', line 700 def define_constant(const_def) name = nil @constants.each do |n, cdef| if cdef == const_def name = n break end end unless name name = "C#{sprintf("%03d", @constants.size)}" @constants << [name, const_def] end name end |
#define_method(vars, &block) ⇒ Object
715 716 717 718 719 |
# File 'lib/amrita2/template.rb', line 715 def define_method(vars, &block) name = "m#{sprintf("%03d", @methods.size)}" @methods << [name, vars, block] name end |
#end_of_module(cg) ⇒ Object
721 722 723 724 725 726 727 728 729 730 |
# File 'lib/amrita2/template.rb', line 721 def end_of_module(cg) @constants.each do |name, defs| cg.code("#{name} = #{defs}") end @methods.each do |name, vars, body| cg.define_method(name, vars) do body.call end end end |