Class: RubyPythonBridge::RubyPyInstance

Inherits:
RubyPyObject show all
Defined in:
lib/rubypython/wrapper_extensions.rb,
ext/rubypython_bridge/rp_object.c

Overview

A wrapper class for Python instances

Instance Method Summary collapse

Methods inherited from RubyPyObject

#__name, #free_pobj, #inspect, #respond_to?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(args) ⇒ Object

:nodoc:



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'ext/rubypython_bridge/rp_object.c', line 212

VALUE rp_inst_delegate(VALUE self,VALUE args)
{
	VALUE name,name_string,rClassDict,result,rInstDict;
	VALUE ret;
	char *cname;
	PObj *pClassDict,*pInstDict;
	PyObject *pCalled;
	
	if(rp_equal(args))
	{
		return rp_inst_attr_set(self,args);
	}
	if(!rp_has_attr(self,rb_ary_entry(args,0)))
	{		
		int argc;
		
		VALUE *argv;
		argc=RARRAY_LEN(args);
		argv=ALLOC_N(VALUE,argc);
		MEMCPY(argv,RARRAY_PTR(args),VALUE,argc);
		return rb_call_super(argc,argv);
	}
	name=rb_ary_shift(args);
	name_string=rb_funcall(name,rb_intern("to_s"),0);
	cname=STR2CSTR(name_string);
		
	rClassDict=rb_iv_get(self,"@pclassdict");
	rInstDict=rb_iv_get(self,"@pinstdict");
	Data_Get_Struct(rClassDict,PObj,pClassDict);
	Data_Get_Struct(rInstDict,PObj,pInstDict);
	pCalled=PyDict_GetItemString(pInstDict->pObject,cname);
	if(!pCalled)
	{
		pCalled=PyDict_GetItemString(pClassDict->pObject,cname);
	}
	Py_XINCREF(pCalled);
	result=ptor_obj_no_destruct(pCalled);
	if(rb_obj_is_instance_of(result,cRubyPyFunction))
	{
		Py_XINCREF(rp_obj_pobject(self));
		rb_ary_unshift(args,self);
		ret=rp_call_func(pCalled,args);
		return ret;
	}
	return result;
	
}