Class: DefModule

Inherits:
ErbPP show all
Includes:
DeclMethod
Defined in:
ext/numo/narray/gen/erbpp2.rb

Direct Known Subclasses

DefClass

Constant Summary

Constants inherited from ErbPP

ErbPP::ATTRS

Instance Attribute Summary

Attributes inherited from ErbPP

#children, #parent

Instance Method Summary collapse

Methods included from DeclMethod

#def_alias, #def_alloc_func, #def_const, #def_method, #def_module_function, #def_singleton_method, #undef_alloc_func, #undef_method, #undef_singleton_method

Methods inherited from ErbPP

#add_child, #attr_method, #attrs, #check_params, define_attrs, #description, #find, #find_tmpl, #get, #has_attr?, #load_erb, #method_missing, #method_missing_alias, #parents, #result, #run, #search_method_in_parents, #set, #write

Constructor Details

#initialize(parent, **opts, &block) ⇒ DefModule

Returns a new instance of DefModule.



165
166
167
168
# File 'ext/numo/narray/gen/erbpp2.rb', line 165

def initialize(parent, **opts, &block)
  eb = opts[:erb_base] || 'module'
  super(parent, erb_base:eb, **opts, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ErbPP

Instance Method Details

#_mod_varObject



185
186
187
# File 'ext/numo/narray/gen/erbpp2.rb', line 185

def _mod_var
  @opts[:module_var]
end

#def_id(name, var = nil) ⇒ Object



172
173
174
175
# File 'ext/numo/narray/gen/erbpp2.rb', line 172

def def_id(name,var=nil)
  var = name.gsub(/\?/,"_p").gsub(/\!/,"_bang") if var.nil?
  id_list << [name,var]
end

#id_listObject



169
170
171
# File 'ext/numo/narray/gen/erbpp2.rb', line 169

def id_list
  @id_list ||= []
end

#init_defObject



176
177
178
# File 'ext/numo/narray/gen/erbpp2.rb', line 176

def init_def
  load_erb(init_erb).result(binding)
end

#init_erbObject



179
180
181
# File 'ext/numo/narray/gen/erbpp2.rb', line 179

def init_erb
  @opts[:init_erb] || "init_module"
end

#method_codeObject



182
183
184
# File 'ext/numo/narray/gen/erbpp2.rb', line 182

def method_code
  @children.map{|c| c.result}.join("\n")
end