2014-08-28 4 views
0

Я хочу получить имя класса класса, который расширил класс. Это предложение, вероятно, не имеет большого смысла, поэтому я объясню в коде.Ruby Class Name

class Alpha 
    store lambda{ 
    # Is it possible to reference 
    # Beta somehow? I need to get 
    # the classname of the extendee, 
    # if that's even a real word. 

    # Returns Alpha, I need Beta. 
    self.name 
    }.call 
end 

class Beta < Alpha; end 

Любые идеи?

ответ

3
class Alpha 
    def self.inherited subclass 
    store lambda{ 
     ... 
     subclass.name 
    }.call 
    end 
end