Class: Function
Overview
Constant Summary
collapse
- DEFS =
[]
Constants inherited
from ErbPP
ErbPP::ATTRS
Instance Attribute Summary
Attributes inherited from ErbPP
#children, #parent
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from ErbPP
#add_child, #attr_method, #attrs, #check_params, define_attrs, #description, #find, #find_tmpl, #get, #has_attr?, #init_def, #load_erb, #method_missing, #method_missing_alias, #parents, #result, #run, #search_method_in_parents, #set, #write
Constructor Details
#initialize(parent, tmpl, **opts) ⇒ Function
Returns a new instance of Function.
168
169
170
171
172
173
174
175
176
|
# File 'lib/erbpp.rb', line 168
def initialize(parent,tmpl,**opts)
super
@aliases = opts[:aliases] || []
parent.tmpl_dirs.each do |d|
@erb_path = File.join(d, tmpl+".c")
break if File.exist?(@erb_path)
end
DEFS.push(self)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class ErbPP
Class Method Details
.codes ⇒ Object
222
223
224
225
226
227
228
229
|
# File 'lib/erbpp.rb', line 222
def self.codes
a = []
DEFS.each do |i|
x = i.code
a.push(x) if x
end
a
end
|
.definitions ⇒ Object
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
# File 'lib/erbpp.rb', line 231
def self.definitions
a = []
DEFS.each do |i|
case x = i.definition
when Array
a.concat(x)
when String
a.push(x)
else
raise "unknown definition: #{x}" if x
end
end
a
end
|
Instance Method Details
#c_func ⇒ Object
Also known as:
c_function, c_instance_method
192
193
194
195
196
197
198
199
200
|
# File 'lib/erbpp.rb', line 192
def c_func
s = singleton ? "_s" : ""
begin
t = "_"+type_name
rescue
t = ""
end
"numo#{t}#{s}_#{method}"
end
|
#c_iter ⇒ Object
Also known as:
c_iterator
182
183
184
185
186
187
188
189
|
# File 'lib/erbpp.rb', line 182
def c_iter
begin
t = "_"+type_name
rescue
t = ""
end
"iter#{t}_#{method}"
end
|
#c_method ⇒ Object
178
179
180
|
# File 'lib/erbpp.rb', line 178
def c_method
"#{m_prefix}#{method}"
end
|
#code ⇒ Object
208
209
210
|
# File 'lib/erbpp.rb', line 208
def code
result + "\n\n"
end
|
#definition ⇒ Object
212
213
214
215
216
217
218
219
220
|
# File 'lib/erbpp.rb', line 212
def definition
return nil if n_arg <= -9
s = singleton ? "_singleton" : ""
check_params(:mod_var, :op_map, :c_func, :n_arg)
m = op_map
a = ["rb_define#{s}_method(#{mod_var}, \"#{m}\", #{c_func}, #{n_arg});"]
@aliases.map{|x| a << "rb_define_alias(#{mod_var}, \"#{x}\", \"#{m}\");"}
a
end
|
#id_op ⇒ Object
156
157
158
159
160
161
162
|
# File 'lib/erbpp.rb', line 156
def id_op
if op.size == 1
"'#{op}'"
else
"id_#{method}"
end
end
|
#method ⇒ Object
164
165
166
|
# File 'lib/erbpp.rb', line 164
def method
meth.gsub(/\?/,"_p").gsub(/\!/,"_bang")
end
|
#op_map ⇒ Object
204
205
206
|
# File 'lib/erbpp.rb', line 204
def op_map
@op || meth
end
|