Class: RubyPythonBridge::RubyPyObject

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

Direct Known Subclasses

RubyPyClass, RubyPyModule

Instance Method Summary collapse

Instance Method Details

#__nameObject

Returns the name of the Python object which this instance wraps.

If it cannot determine a reasonable name it just gives up.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'ext/rubypython_bridge/rp_object.c', line 105

static
VALUE rpObjectectGetName(VALUE self)
{
	//It only makes sense to query a python object if the interpreter is running.
	if(Py_IsInitialized())
	{
		PyObject *pObject,*pName,*pRepr;
		VALUE rName;
		
		pObject = rpObjectGetPyObject(self);
		
		
		pName = PyObject_GetAttrString(pObject,"__name__");
		
		if(!pName)
		{
			PyErr_Clear();
			
			pName = PyObject_GetAttrString(pObject,"__class__");
	 		pRepr = PyObject_Repr(pName);
			rName = ptorString(pRepr);
			Py_XDECREF(pRepr);
			
			return rb_str_concat(rb_str_new2("An instance of "), rName);
			if(!pName)
			{
				PyErr_Clear();
				
				pName = PyObject_Repr(pObject);
				
				if(!pName)
				{
					PyErr_Clear();
					return rb_str_new2("__Unnameable__");
				}
			}
		}
		
		rName = ptorString(pName);
		
		Py_XDECREF(pName);
		
		return rName;
	}
	
	return rb_str_new2("__FREED__");

}

#free_pobjObject

Decreases the reference count on the object wrapped by this instance. This is used for cleanup in RubyPython.stop. RubyPyObject instances automatically decrease the reference count on their associated objects before they are garbage collected.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'ext/rubypython_bridge/rp_object.c', line 48

static
VALUE rpObjectFreePobj(VALUE self)
{
	PObj *cself;
	
	Data_Get_Struct(self, PObj, cself);
	
	if(Py_IsInitialized() && cself->pObject)
	{
		Py_XDECREF(cself->pObject);
		cself->pObject = NULL;
		return Qtrue;
	}
	else
	{
		cself->pObject = NULL;
	}
	
	return Qfalse;
}

#inspectObject



3
4
5
# File 'lib/rubypython/wrapper_extensions.rb', line 3

def inspect
  "<#{self.class}:#{__name}>"
end

#respond_to?(mname) ⇒ Boolean

Tests whether the wrapped object will respond to the given method

Returns:

  • (Boolean)


169
170
171
172
173
174
175
176
177
# File 'ext/rubypython_bridge/rp_object.c', line 169

VALUE rpRespondsTo(VALUE self, VALUE mname)
{
	if(rpHasSymbol(self, mname))
	{
		return Qtrue;
	}
	
	return Qfalse;
}