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:



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'ext/rubypython_bridge/rp_object.c', line 136

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_has_attr(self,rb_ary_entry(args,0)))
  {    
    int argc;
    
    VALUE *argv;
    argc=RARRAY(args)->len;
    argv=ALLOC_N(VALUE,argc);
    MEMCPY(argv,RARRAY(args)->ptr,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;
  
}