2014-08-28 20 views
0

我想獲得擴展類的類的類名。這句話可能沒有多大意義,所以我會在代碼中解釋。Ruby類名

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