Class: DefModule

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

Direct Known Subclasses

DefClass

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, #description, #find, #find_tmpl, #get, #load_erb, #method_missing, #method_missing_alias, #result, #run, #set, #write

Constructor Details

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

Returns a new instance of DefModule.



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

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



190
191
192
# File 'ext/numo/narray/gen/erbpp2.rb', line 190

def _mod_var
  @opts[:module_var]
end

#def_id(name, var = nil) ⇒ Object



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

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

#id_listObject



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

def id_list
  @id_list ||= []
end

#init_defObject



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

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

#init_erbObject



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

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

#method_codeObject



187
188
189
# File 'ext/numo/narray/gen/erbpp2.rb', line 187

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