跳轉到內容

Ruby 程式設計/語法/鉤子

來自 WikiBooks,開放世界上的開放圖書

Ruby 提供回撥,例如用於識別在(後期)類中定義新方法的時間。

此處提供了已知回撥列表。

const_missing

[編輯 | 編輯原始碼]
class Object
  def self.const_missing c
    p 'missing const was', c
  end
end

或更多

class Object
  class << self
    alias :const_missing_old :const_missing
    def const_missing c
      p 'const missing is', c
      const_missing_old c
    end
  end
end
華夏公益教科書