Class: DefMethod

Inherits:
ErbPP show all
Includes:
DeclMethod
Defined in:
ext/numo/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.



217
218
219
220
# File 'ext/numo/narray/gen/erbpp2.rb', line 217

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



238
239
240
241
242
# File 'ext/numo/narray/gen/erbpp2.rb', line 238

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



244
245
246
# File 'ext/numo/narray/gen/erbpp2.rb', line 244

def c_iter
  "iter_#{c_func}"
end

#c_nameObject



230
231
232
# File 'ext/numo/narray/gen/erbpp2.rb', line 230

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

#define_method_argsObject



248
249
250
# File 'ext/numo/narray/gen/erbpp2.rb', line 248

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

#id_opObject



222
223
224
225
226
227
228
# File 'ext/numo/narray/gen/erbpp2.rb', line 222

def id_op
  if op.size == 1
    "'#{op}'"
  else
    "id_#{c_name}"
  end
end

#init_defObject



252
253
254
255
256
# File 'ext/numo/narray/gen/erbpp2.rb', line 252

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

#op_mapObject



234
235
236
# File 'ext/numo/narray/gen/erbpp2.rb', line 234

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

#singletonObject



258
259
260
# File 'ext/numo/narray/gen/erbpp2.rb', line 258

def singleton
  @opts[:singleton]
end