Ilmari Heikkinen
5/3/2005 6:46:00 PM
On 3.5.2005, at 21:24, Ara.T.Howard@noaa.gov wrote:
> On Tue, 3 May 2005, Robert Klemme wrote:
>
>> Ara.T.Howard wrote:
>>> thoughts on how to do this
>>>
>>> class C
>>> class << self
>>> p un_metaclass #=> C
>>> end
>>> end
>>>
>>> ??
>>
>> I'd prefer to call it #instance 'cause that's what it is. :-)
>
>
> hmmm. ok. any ideas? i'm playing with nesting and ancestors - but
> no luck.
>
There's this terrible hack:
class Class
def un_metaclass
to_s.scan(/:[^A-Z]*(([A-Za-z0-9]*(::)?)+)/)[0][0].
split("::").inject(Object){|m, n| m.const_get(n)}
end
end
It's not something I'd like to use though :-)