Ruby类名

时间:2014-08-28 02:21:24

标签: ruby class inheritance

我想获得扩展了类的类的类名。这句话可能没有多大意义,所以我将在代码中解释。

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

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

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