[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Getting class name without module

Jari Williamsson

2/12/2008 12:06:00 PM

Is there a method available to get only the class name, without getting
the module name prior to it? Alternatively, to get the class name within
the current name space context?

For example, self.class could return something like this:
MyModule::MyClass
(I would like to only get the "MyClass" part.)

Or do I have to resort to string manipulation/regexps?


Best regards,

Jari Williamsson

1 Answer

Xavier Noria

2/12/2008 12:34:00 PM

0

On Feb 12, 2008, at 13:05 , Jari Williamsson wrote:

> Is there a method available to get only the class name, without
> getting the module name prior to it? Alternatively, to get the class
> name within the current name space context?
>
> For example, self.class could return something like this:
> MyModule::MyClass
> (I would like to only get the "MyClass" part.)
>
> Or do I have to resort to string manipulation/regexps?

Indeed, you do it by hand, something like this:

name.split('::').last || ''

-- fxn