【问题标题】:Ruby Class Name [duplicate]Ruby 类名 [重复]
【发布时间】:2014-08-28 02:21:23
【问题描述】:

我想获取扩展类的类的类名。那句话可能没有多大意义,所以我会用代码解释。

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

有什么想法吗?

【问题讨论】:

    标签: ruby class inheritance


    【解决方案1】:
    class Alpha
      def self.inherited subclass
        store lambda{
          ...
          subclass.name
        }.call
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-28
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多