Class: DefMethod

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

Direct Known Subclasses

DefAllocFunc, DefModuleFunction, Store

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, erb_base, **opts, &block) ⇒ DefMethod

Returns a new instance of DefMethod.



224
225
226
227
# File 'ext/cumo/narray/gen/erbpp2.rb', line 224

def initialize(parent, erb_base, **opts, &block)
  super(parent, **opts, &block)
  set erb_base: erb_base
end

Dynamic Method Handling

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

Instance Method Details

#c_func(n_arg = nil) ⇒ Object



245
246
247
248
249
# File 'ext/cumo/narray/gen/erbpp2.rb', line 245

def c_func(n_arg=nil)
  set n_arg: n_arg if n_arg
  s = (singleton) ? "_s" : ""
  "#{@parent.name}#{s}_#{c_name}"
end

#c_iterObject



251
252
253
# File 'ext/cumo/narray/gen/erbpp2.rb', line 251

def c_iter
  "iter_#{c_func}"
end

#c_nameObject



237
238
239
# File 'ext/cumo/narray/gen/erbpp2.rb', line 237

def c_name
  @opts[:name].gsub(/\?/,"_p").gsub(/\!/,"_bang").gsub(/=/,"_set")
end

#cumo_id_opObject



229
230
231
232
233
234
235
# File 'ext/cumo/narray/gen/erbpp2.rb', line 229

def cumo_id_op
  if op.size == 1
    "'#{op}'"
  else
    "cumo_id_#{c_name}"
  end
end

#define_method_argsObject



255
256
257
# File 'ext/cumo/narray/gen/erbpp2.rb', line 255

def define_method_args
  "#{_mod_var}, \"#{op_map}\", #{c_func}, #{n_arg}"
end

#init_defObject



259
260
261
262
263
# File 'ext/cumo/narray/gen/erbpp2.rb', line 259

def init_def
  return if n_arg == :nodef
  s = (singleton) ? "_singleton" : ""
  "rb_define#{s}_method(#{define_method_args});"
end

#op_mapObject



241
242
243
# File 'ext/cumo/narray/gen/erbpp2.rb', line 241

def op_map
  @opts[:op] || @opts[:name]
end

#singletonObject



265
266
267
# File 'ext/cumo/narray/gen/erbpp2.rb', line 265

def singleton
  @opts[:singleton]
end