开发者

Rails: Overriding const_missing within a module

开发者 https://www.devze.com 2023-01-08 10:55 出处:网络
Within my Rails application I have a module defined this way: module WhateverModule class WhateverClass

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

精彩评论

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