# Getting the runtime type

**URL:** <https://www.ruby-forum.com/t/getting-the-runtime-type/179579>\
**Category:** IronRuby\
**Created:** [November 29, 2009, 10:07am UTC](https://www.ruby-forum.com/t/getting-the-runtime-type/179579 "2009-11-29T10:07:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [November 29, 2009, 10:07am UTC](https://www.ruby-forum.com/t/getting-the-runtime-type/179579/1 "2009-11-29T10:07:23Z")

</div>

Hi

I’d like to get the runtime type of a ruby class

The IronPython guys can do something like this (python substituted for  
ruby)  
require ‘clr’

class Person \< Struct.new(:id, :name, :age)  
end

they can then do clr.ClrType(Person).FullName

Something equivalent to that doesn’t exist yet for ironruby does it?

When I do Person.to\_clr\_type it returns nil  
and other objects give me their base types

Person.GetType =\> IronRuby.Builtins.RubyObject

## I’m actually trying to get the ironpython ClrMetaClass from Harry Pierson written in ironruby.

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Google Wave: removed\_email\_address@domain.invalid  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [November 29, 2009, 3:01pm UTC](https://www.ruby-forum.com/t/getting-the-runtime-type/179579/2 "2009-11-29T15:01:46Z")

</div>

Every Ruby class is not mapped to a unique CLR type (they are all  
IronRuby.Builtins.RubyObject unless you subclass a CLR type or implement  
and interface). So doing the IronPython ClrMetaClass equivalent would  
require a speciic feature in IronRuby to give more control of the  
underlying CLR type – IronPython has already added this in the form of  
“ **clrtype** ”.

This work is not planned for 1.0, but definitely leaves a usability hole  
in our CLR integration. The work-around is to create a empty C# class,  
and then subclass it from Ruby – there will be a unique CLR class  
generated for this Ruby class. Things like CLR attributes need to go on  
the C# class.

~Jimmy  
Sent from my phone

On Nov 29, 2009, at 4:07 AM, “Ivan Porto C.”  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

Hi

I’d like to get the runtime type of a ruby class

The IronPython guys can do something like this (python substituted for  
ruby)  
require ‘clr’

class Person \< Struct.new(:id, :name, :age)  
end

they can then do clr.ClrType(Person).FullName

Something equivalent to that doesn’t exist yet for ironruby does it?

When I do Person.to\_clr\_type it returns nil  
and other objects give me their base types

Person.GetType =\> IronRuby.Builtins.RubyObject

## I’m actually trying to get the ironpython ClrMetaClass from Harry Pierson written in ironruby.

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz) [http://flanders.co.nz](http://flanders.co.nz)  
Google Wave: [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim) [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action  
([http://manning.com/carrero](http://manning.com/carrero)[http://manning.com/carrero](http://manning.com/carrero))

* * *

Ironruby-core mailing list  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [November 29, 2009, 8:40pm UTC](https://www.ruby-forum.com/t/getting-the-runtime-type/179579/3 "2009-11-29T20:40:02Z")

</div>

Is the current best practice for this to create a custom class for any  
Ruby  
types that need CLR integration, or should we use  
IronRubyInline[http://github.com/rvernagus/IronRubyInline](http://github.com/rvernagus/IronRubyInline)?  
I suppose it depends on your use case, but I would think the latter is  
probably the best option. Thoughts?

Ryan R.

Email: removed\_email\_address@domain.invalid  
LinkedIn: [http://www.linkedin.com/in/ryanriley](http://www.linkedin.com/in/ryanriley)  
Blog: [http://wizardsofsmart.net/](http://wizardsofsmart.net/)  
Website: [http://panesofglass.org/](http://panesofglass.org/)

On Sun, Nov 29, 2009 at 8:00 AM, Jimmy S. \<

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [November 29, 2009, 8:54pm UTC](https://www.ruby-forum.com/t/getting-the-runtime-type/179579/4 "2009-11-29T20:54:05Z")

</div>

## I want to use it for silverlight databinding, but it’s part of a bigger plan 🙂

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Google Wave: removed\_email\_address@domain.invalid  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [November 29, 2009, 9:25pm UTC](https://www.ruby-forum.com/t/getting-the-runtime-type/179579/5 "2009-11-29T21:25:06Z")

</div>

IronRubyInline gives you a better workflow between writing C# and Ruby,  
so it gives you nice way to create a CLR type, but both ways are  
techically equivalent, so either way is fine. Personally I’d use the  
inline option.

Keep in mind that ironrubyinline requires you to be able to call csc.exe  
and write a DLL to disk at runtime, so make sure your environment  
supports that – you might need to pregen the dlls in a partial trust,  
for example, but for development it’s perfectly fine.

~Jimmy  
Sent from my phone

On Nov 29, 2009, at 2:40 PM, “Ryan R.”  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

Is the current best practice for this to create a custom class for any  
Ruby types that need CLR integration, or should we use  
IronRubyInline[http://github.com/rvernagus/IronRubyInline](http://github.com/rvernagus/IronRubyInline)? I suppose it  
depends on your use case, but I would think the latter is probably the  
best option. Thoughts?

Ryan R.

Email: [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
LinkedIn: [http://www.linkedin.com/in/ryanriley](http://www.linkedin.com/in/ryanriley)  
[http://www.linkedin.com/in/ryanriley](http://www.linkedin.com/in/ryanriley)  
Blog: [http://wizardsofsmart.net/](http://wizardsofsmart.net/) [http://wizardsofsmart.net/](http://wizardsofsmart.net/)  
Website: [http://panesofglass.org/](http://panesofglass.org/) [http://panesofglass.org/](http://panesofglass.org/)

On Sun, Nov 29, 2009 at 8:00 AM, Jimmy S.  
\<[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\>  
wrote:  
Every Ruby class is not mapped to a unique CLR type (they are all  
IronRuby.Builtins.RubyObject unless you subclass a CLR type or implement  
and interface). So doing the IronPython ClrMetaClass equivalent would  
require a speciic feature in IronRuby to give more control of the  
underlying CLR type – IronPython has already added this in the form of  
“ **clrtype** ”.

This work is not planned for 1.0, but definitely leaves a usability hole  
in our CLR integration. The work-around is to create a empty C# class,  
and then subclass it from Ruby – there will be a unique CLR class  
generated for this Ruby class. Things like CLR attributes need to go on  
the C# class.

~Jimmy  
Sent from my phone

On Nov 29, 2009, at 4:07 AM, “Ivan Porto C.”  
\<[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\>  
wrote:

Hi

I’d like to get the runtime type of a ruby class

The IronPython guys can do something like this (python substituted for  
ruby)  
require ‘clr’

class Person \< Struct.new(:id, :name, :age)  
end

they can then do clr.ClrType(Person).FullName

Something equivalent to that doesn’t exist yet for ironruby does it?

When I do Person.to\_clr\_type it returns nil  
and other objects give me their base types

Person.GetType =\> IronRuby.Builtins.RubyObject

## I’m actually trying to get the ironpython ClrMetaClass from Harry Pierson written in ironruby.

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz) [http://flanders.co.nz](http://flanders.co.nz)

> **[Ivan Porto Carrero](http://flanders.co.nz)**
>
> Last week we released Scalatra 2.2. This is our biggest release so far and introduces a bunch of exciting features like commands for handling input, …

Google Wave: [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim) [http://twitter.com/casualjim](http://twitter.com/casualjim)  
[http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action  
([http://manning.com/carrero](http://manning.com/carrero)[http://manning.com/carrero](http://manning.com/carrero)[http://manning.com/carrero](http://manning.com/carrero))

* * *

Ironruby-core mailing list  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

* * *

Ironruby-core mailing list  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

* * *

Ironruby-core mailing list  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)
