2014-08-28 2 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