开发者

Rails: Overriding const_missing within a module

Within my Rails application I have a module defined this way:

module WhateverModule
  class WhateverClass
    ...
  end
end

This file (whatever_class.rb) is located under /app/models/whatever_module

const_missing is being overriden by Rails and despite I did some workarounds, involving initializers, I wish I could make it in a better way.

My aim is to get a W开发者_JS百科hateverModule::Foo (Foo being undefined) to be resolved by a custom const_missing method.

Any help will be greatly appreciated. Thanks in advance!!


The following seems to work fine for me in Rails 2.2.2

module WhateverModule
  def self.const_missing(c)
     # handle missing constant
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜