# From String to T\_STRING

**URL:** <https://www.ruby-forum.com/t/from-string-to-t-string/132875>\
**Category:** Ruby\
**Created:** [March 25, 2008, 2:26pm UTC](https://www.ruby-forum.com/t/from-string-to-t-string/132875 "2008-03-25T14:26:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [March 25, 2008, 2:26pm UTC](https://www.ruby-forum.com/t/from-string-to-t-string/132875/1 "2008-03-25T14:26:02Z")

</div>

Hi,

i have a method, wich is called with type identifiers like this:

my\_method(Sting, Fixnum)

this method is implemented in a C extension. In this extension it is  
easy to get the name of the parameters with rb\_class2name. But how can i  
get the types like T\_STRING or T\_FIXNUM? If i use BUILTIN\_TYPE or TYPE i  
get T\_CLASS.

Cheers, detlef

---

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [March 26, 2008, 11:02pm UTC](https://www.ruby-forum.com/t/from-string-to-t-string/132875/2 "2008-03-26T23:02:24Z")

</div>

On Mar 25, 2008, at 06:24 AM, Detlef R. wrote:

> TYPE i  
> get T\_CLASS.

I’m guessing your C implementation looks something like:

my\_method(VALUE a, VALUE b) {  
}

Since you’ve passed in the String and Fixnum classes, the C type of  
the RObject your VALUE points to is T\_STRING. If you want an RObject  
with a C type of T\_STRING or T\_FIXNUM you’ll have to pass in a String  
object like “foo” or Fixnum like 5.

If your C function must be passed a String and a Fixnum object, you’ll  
need to do duck-type checking, rb\_check\_string\_type() and maybe  
rb\_Integer() or rb\_to\_int().
