Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #6688 > unrolled thread
| Started by | irio.musskopf@caixadeideias.com.br |
|---|---|
| First post | 2012-12-04 11:24 -0800 |
| Last post | 2012-12-05 08:19 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.ruby
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
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
| From | irio.musskopf@caixadeideias.com.br |
|---|---|
| Date | 2012-12-04 11:24 -0800 |
| Subject | Re: Getting class name without module |
| Message-ID | <8f6226ce-4519-4e72-a3d1-e55637fcba45@googlegroups.com> |
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? > > > Best regards, > > Jari Williamsson 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? > > > Best regards, > > Jari Williamsson If you are using ActiveSupport: MyModule::MyClass.to_s.demodulize # => "MyClass"
[toc] | [next] | [standalone]
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Date | 2012-12-05 08:19 +0100 |
| Message-ID | <ai8ar7F40v5U1@mid.individual.net> |
| In reply to | #6688 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.ruby
csiph-web