On 12/04/2012 08:24 PM,
wrote:
> Em terça-feira, 12 de fevereiro de 2008 10h05min31s UTC-2, Jari Williamsson escreveu:
>> 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?
irb(main):001:0> module X; class Y; end end
=> nil
irb(main):002:0> X::Y.name
=> "X::Y"
irb(main):003:0> X::Y.name.split(/::/).last
=> "Y"
irb(main):004:0> X::Y.name.split('::').last
=> "Y"
Cheers
robert