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.



226
227
228
229
# File 'ext/cumo/narray/gen/erbpp2.rb', line 226

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



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

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



253
254
255
# File 'ext/cumo/narray/gen/erbpp2.rb', line 253

def c_iter
  "iter_#{c_func}"
end

#c_nameObject



239
240
241
# File 'ext/cumo/narray/gen/erbpp2.rb', line 239

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

#cumo_id_opObject



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

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

#define_method_argsObject



257
258
259
# File 'ext/cumo/narray/gen/erbpp2.rb', line 257

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

#init_defObject



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

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

#op_mapObject



243
244
245
# File 'ext/cumo/narray/gen/erbpp2.rb', line 243

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

#singletonObject



267
268
269
# File 'ext/cumo/narray/gen/erbpp2.rb', line 267

def singleton
  @opts[:singleton]
end