【问题标题】:can't load require_dependency无法加载 require_dependency
【发布时间】:2012-06-13 19:25:42
【问题描述】:

我正在尝试使用来自ActiveSupport 库的require_dependency 进行撬动:

require 'active_support'  #=> true
require_dependency 'test' #=> NoMethodError: undefined method  
                          #=> `require_dependency' for main:Object

可能是什么问题?

【问题讨论】:

    标签: ruby activesupport


    【解决方案1】:

    ActiveSupport 过去非常邪恶,因为它在 require 上加载了大量的东西。 “厨房水槽”方法打开了许多核心类并改变了它们的行为(如 JSON)。这导致了与其他 gem 和代码的不兼容/问题,这些 gem 和代码期望核心 ruby​​ 函数表现得像它们的香草本身。

    所以现在只需要 active_support 不会加载任何内容。

    http://edgeguides.rubyonrails.org/active_support_core_extensions.html

    在您的情况下,您可能需要require 'active_support/core_ext'

    【讨论】:

    • 它适用于这一行:require 'active_support/dependencies'
    • 是的,谢谢它会帮助未来看到这个的人。
    猜你喜欢
    • 2010-11-30
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    • 2011-01-24
    • 2010-10-21
    • 1970-01-01
    • 1970-01-01
    • 2019-12-11
    相关资源
    最近更新 更多