草庐IT

javascript - RequireJS 和 JS 模块模式

全部标签

ruby - 加载两个同名的 Ruby 模块/Gems

我正在尝试使用两个Gem访问AmazonWebServices(AWS)。一个是亚马逊的“aws-sdk”,另一个是“amazon-ec2”。我使用的是第二个,因为aws-sdk不涵盖亚马逊服务的cloudwatch部分。问题是两者都加载到同一个命名空间中。require'aws-sdk'#aws-sdkgemrequire'AWS'#amazon-ec2gemconfig={:access_key_id=>'abc',:secret_key=>'xyz'}#startusingtheAPIwithaws-sdkec2=AWS::EC2.new(config)#startusingth

ruby-on-rails - 无法安装乘客模块

我正在尝试为Rails应用程序配置passenger和Nginx。我在执行乘客命令时遇到编译错误。ruby版本:ruby2.3.1p112(2016-04-26修订版54768)[x86_64-linux]Rails版本rails4.2.6错误信息:-#passenger-install-nginx-module/usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/specification.rb:2158:in`method_missing':undefinedmethod`this'for#(NoMethodError)f

ruby - 优雅的方式添加到已经包含的模块?

我想对一个gem进行猴子修补,目标代码在一个模块中。不幸的是,在我预先准备我的补丁时,该模块已经包含在各种类中,新代码无效。例子:moduleFeaturedefactionputs"Feature"endendmodulePatchdefactionputs"Patch"endendclassBase1includeFeatureendFeature.prependPatchclassBase2includeFeatureendBase1.new.action#Returns"Feature",Iwantittobe"Patch"instead.Base2.new.action#Re

ruby-on-rails - 命名空间模块和 Rails 3.1.3 autoload_path

我在为包含在模型中的模块命名空间时遇到了一些麻烦。在/app/models/car.rb中classCarincludeSearch::Carend在/lib/search/car.rb中moduleSearchmoduleCarincludeActiveSupport::Concern#methodsinhereendend在/config/application.rb中config.autoload_paths+=Dir["#{config.root}/lib/**/"]config.autoload_paths+=Dir["#{config.root}/lib/search/*"

ruby - 重开Ruby嵌套模块异常

为什么重新打开嵌套模块会根据使用的语法给出不同的结果?例如,这很好用:moduleAmoduleEendendmoduleAmoduleEdefE.eendendend但是这个:moduleAmoduleEendendmoduleA::EdefE.eendend给出错误:reopen.rb:6:in`':uninitializedconstantA::E::E(NameError)fromreopen.rb:5:in`'(在有人指出这一点之前,解决方法是在定义E.e时使用self而不是模块名称,但这不是本文的重点。) 最佳答案 mo

ruby FTP被动模式错误

我试过在被动模式下使用FTP:require'net/ftp'ftp=Net::FTP.newftp.passive=trueftp.connect('mydomain.com')ftp.loginfilenames=ftp.nlst但是有错误:Errno::ETIMEDOUT:Connectiontimedout-connect(2)虽然在事件模式下它工作正常!我使用ruby​​1.9.3。当我设置Debug模式时:ftp.debug_mode=true我明白了:**ftp.connect('mydomain.com')**connect:mydomain.com,21get:220

ruby - 在模块中扩展类方法

我正在使用ruby​​的元编程功能,我发现它有点毛茸茸。我正在尝试使用模块包装方法调用。目前,我正在这样做:moduleBarmoduleClassMethodsdefwrap(method)class_evaldoold_method="wrapped_#{method}".to_symunlessrespond_to?old_methodalias_methodold_method,methoddefine_methodmethoddo|*args|sendold_method,*argsendendendendenddefself.included(base)base.exten

ruby-on-rails - 每次请求都会重新加载模块,因此初始化数据会丢失

我将值存储在模块内的类变量中,例如:moduleTranslationEnhancerdefself.install!klass@dictionaries||=[]我从config/initializers中的初始化程序中调用它:requireRails.root+"lib"+"translation_enhancer.rb"TranslationEnhancer::install!TranslationDictionary现在,如果我在开发环境中启动服务器,在第一个请求期间一切正常。然而,在那个请求之后,@dictionaries突然变成了nil。我已经注释了TranslationE

ruby - 在另一个模块中包含一个模块

moduleA;defa;end;endmoduleB;defb;end;endclassC;includeA;endmoduleA;includeB;endclassD;includeA;endC.new.b#undefinedmethoderrorD.new.b#nilC.ancestors#[C,A,Object...]D.ancestors#[D,A,B,Object...]如何将模块B包含在A中,以便已经包含模块A的类也可以从模块B获取方法? 最佳答案 如前所述,Ruby不是这样工作的-当一个类包含一个模块时,它不会保留对

ruby-on-rails - 如何在 Rails 应用程序中使用模块

我刚刚在/lib文件夹中创建了一个模块location.rb,其内容如下:moduleLocationdefself.my_zipcode()zip_code="11215"endend现在在我的Controller中我尝试调用“my_zipcode”方法:classDirectoryController但是它抛出一个错误:undefinedmethod`my_zipcode'forLocation:Module 最佳答案 您还可以将以下内容添加到您的config/application.rbconfig.autoload_path