Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #6689
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: Getting class name without module |
| Date | 2012-12-05 08:19 +0100 |
| Message-ID | <ai8ar7F40v5U1@mid.individual.net> (permalink) |
| References | <47B18B80.9090204@mailbox.swipnet.se> <8f6226ce-4519-4e72-a3d1-e55637fcba45@googlegroups.com> |
On 12/04/2012 08:24 PM, irio.musskopf@caixadeideias.com.br 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
Back to comp.lang.ruby | Previous | Next — Previous in thread | Find similar
Re: Getting class name without module irio.musskopf@caixadeideias.com.br - 2012-12-04 11:24 -0800 Re: Getting class name without module Robert Klemme <shortcutter@googlemail.com> - 2012-12-05 08:19 +0100
csiph-web