jjzjj

lazy-loading

全部标签

ruby - 加载错误 : cannot load such file -- rspec/core/rake_task

当我rake的时候,我得到了这个错误。AllenLins-MacBook-Pro:geoblacklightallenlin$rake-tResolvingdependencies...Youmust`geminstallbundler`and`bundleinstall`torunraketasksrakeaborted!LoadError:cannotloadsuchfile--rspec/core/rake_task/Users/allenlin/Documents/USpatial/geoblacklight/Rakefile:12:in`require'/Users/alle

ruby-on-rails - ruby 错误 : cannot load such file -- rest-client

我正在使用RubyonRails4。我正在努力require'rest-client'在我的Controller中,以便我可以解析从表单中获取的登录信息并将其发送到API。我可以验证gem是否已安装并且也在我的应用程序根目录下的Gemfile中。但是,当我尝试在我的Controller中请求该文件时,它仍然抛出“无法加载此类文件--rest-client”。我用谷歌搜索了这个错误,我看到的大部分答案要么是gem没有安装,要么不在Gemfile中,要么是两者兼而有之。这里的情况也不是。我的Controller是否由于某种原因无法访问rest-clientgem?我必须使用rest-cli

ruby-on-rails - 在 `require' : no such file to load -- iconv (LoadError)

➜expertizagit:(master)✗ruby-vruby1.8.7(2011-06-30patchlevel352)[i686-darwin11.1.0]➜expertizagit:(master)✗rails-vRails2.3.14➜expertizagit:(master)✗script/server/Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support/inflector.rb:3:in`require':nosuchfiletoload--iconv(Load

ruby - 使用 WWW :Mechanize to download a file to disk without loading it all in memory first

我正在使用Mechanize来简化某些文件的下载。目前我的脚本使用以下行来实际下载文件...agent.get('http://example.com/foo').save_as'a_file_name'然而,这会将完整的文件下载到内存中,然后再将其转储到磁盘。你如何绕过这种行为,直接下载到磁盘?如果我需要使用WWW:Mechanize以外的东西,那么我将如何使用WWW:Mechanize的cookies呢? 最佳答案 您真正想要的是Mechanize::Downloadhttp://mechanize.rubyforge.org/

ruby-on-rails - CanCan load_and_authorize_resource 触发 Forbidden Attributes

我有一个使用强参数的标准RESTfulController。classUsersController在我的config/initializers中,我有文件strong_parameters.rbActiveRecord::Base.send(:include,ActiveModel::ForbiddenAttributesProtection)当我向CanCan的load_and_authorize_resource添加一个简单的调用时,我得到了1)UsersControllerPOSTcreatewithinvalidparamsre-rendersthe'new'template

ruby - Ruby 中的惰性求值

我有一个Ruby的情况,其中可能需要创建一个对象,但不确定。由于对象的创建可能代价高昂,我不太急于创建它。我认为这是延迟加载的明显案例。如何定义一个仅在有人向其发送消息时才创建的对象?该对象将在block中创建。有没有一种方法可以在Ruby中进行简单的延迟加载/初始化?这些东西是否得到某些gem的支持,它们为对象的延迟初始化的各种情况提供了不同的解决方案?感谢您的建议! 最佳答案 有两种方法。第一个是让调用者处理惰性对象创建。这是最简单的解决方案,也是Ruby代码中非常常见的模式。classExpensiveObjectdefini

ruby - 在没有 `autoload` 的情况下在 Ruby 中自动加载类

我爱theautoloadfunctionalityofRuby;然而,它是goingawayinfutureversionsofRuby因为它从来都不是线程安全的。所以现在我想假装它已经消失并在没有它的情况下编写我的代码,方法是自己实现延迟加载机制。我想以最简单的方式实现它(我现在不关心线程安全)。Ruby应该允许我们这样做。让我们从扩充一个类开始const_missing:classDummydefself.const_missing(const)puts"const_missing(#{const.inspect})"super(const)endend当我们尝试引用“Dummy

ruby LoadError : cannot load such file

例如,当我需要一个文件(称为st.rb)时:require'rubygems'require'mongrel'classTestHandler在irb中我得到:>>require'st.rb'LoadError:cannotloadsuchfile--st.rbfrom/usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in`require'from/usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in`require'from(irb):3from/usr/loc

ruby - load 在本地路径上工作,require 不

加载器.rbputs'>Thisisthesecondfile.'加载演示.rbputs'Thisisthefirst(master)programfile.'load'loadee.rb'puts'Andbackagaintothefirstfile.'当我运行"rubyloaddemo.rb"时,效果很好。这两个文件都在同一个目录中,这就是我运行的目录。但是,如果我将负载更改为要求,无论有无扩展名,我都会得到::29:in`require':nosuchfiletoload--loadee.rb(LoadError)from:29:in`require'fromloaddemo.r

ruby -v dyld : Library not loaded:/usr/local/lib/libgmp. 10.dylib

我一直在尝试在终端中运行脚本,每次我都会得到:$rubydirectory.rbdyld:Librarynotloaded:/usr/local/lib/libgmp.10.dylibReferencedfrom:/Users/claretrembath/.rvm/rubies/ruby-2.1.3/bin/rubyReason:imagenotfoundTrace/BPTtrap:5我意识到在检查ruby-v时我得到了相同的输出:$ruby-vdyld:Librarynotloaded:/usr/local/lib/libgmp.10.dylibReferencedfrom:/Use