Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.datemas.de!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.ruby Subject: Re: Getting class name without module Date: Wed, 05 Dec 2012 08:19:03 +0100 Lines: 28 Message-ID: References: <47B18B80.9090204@mailbox.swipnet.se> <8f6226ce-4519-4e72-a3d1-e55637fcba45@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: individual.net bzAfzT1kZormoHnDE5nAWgrp0iBIdqRUnCvmdw/6JlfME4y5ZDtDxjmznPkcFr7PM= Cancel-Lock: sha1:lOQvYx0UbjZ6R0z7mtf3p1Gc2mk= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: <8f6226ce-4519-4e72-a3d1-e55637fcba45@googlegroups.com> Xref: csiph.com comp.lang.ruby:6689 On 12/04/2012 08:24 PM, irio.musskopf@caixadeideias.com.br wrote: > Em ter=E7a-feira, 12 de fevereiro de 2008 10h05min31s UTC-2, Jari Willi= amsson escreveu: >> Is there a method available to get only the class name, without gettin= g >> the module name prior to it? Alternatively, to get the class name with= in >> 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 =3D> nil irb(main):002:0> X::Y.name =3D> "X::Y" irb(main):003:0> X::Y.name.split(/::/).last =3D> "Y" irb(main):004:0> X::Y.name.split('::').last =3D> "Y" Cheers robert