Class: DefMethod
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, erb_base, **opts, &block) ⇒ DefMethod
Returns a new instance of DefMethod.
212
213
214
215
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 212
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
233
234
235
236
237
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 233
def c_func(n_arg=nil)
set n_arg: n_arg if n_arg
s = (singleton) ? "_s" : ""
"#{@parent.name}#{s}_#{c_name}"
end
|
#c_iter ⇒ Object
239
240
241
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 239
def c_iter
"iter_#{c_func}"
end
|
#c_name ⇒ Object
225
226
227
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 225
def c_name
@opts[:name].gsub(/\?/,"_p").gsub(/\!/,"_bang").gsub(/=/,"_set")
end
|
#define_method_args ⇒ Object
243
244
245
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 243
def define_method_args
"#{_mod_var}, \"#{op_map}\", #{c_func}, #{n_arg}"
end
|
#id_op ⇒ Object
217
218
219
220
221
222
223
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 217
def id_op
if op.size == 1
"'#{op}'"
else
"id_#{c_name}"
end
end
|
#init_def ⇒ Object
247
248
249
250
251
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 247
def init_def
return if n_arg == :nodef
s = (singleton) ? "_singleton" : ""
"rb_define#{s}_method(#{define_method_args});"
end
|
#op_map ⇒ Object
229
230
231
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 229
def op_map
@opts[:op] || @opts[:name]
end
|
#singleton ⇒ Object
253
254
255
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 253
def singleton
@opts[:singleton]
end
|