草庐IT

return-type-requirement

全部标签

ruby - require ruby​​gems 如何帮助查找 ruby​​gem 文件?

在尝试解决Gemfoundinirb,notinRuby时,我试着看看require'rubygems'对我自己的安装有什么影响:$irbirb(main):001:0>RUBY_VERSION=>"1.8.7"irb(main):002:0>$:["/usr/local/lib/site_ruby/1.8","/usr/local/lib/site_ruby/1.8/x86_64-linux","/usr/local/lib/site_ruby","/usr/lib/ruby/vendor_ruby/1.8","/usr/lib/ruby/vendor_ruby/1.8/x86_64

ruby-on-rails - capistrano - NameError:未初始化的常量 Net::SSH::KnownHosts::SUPPORTED_TYPE

我正在尝试将我的Rails(3.1.3)应用程序部署到预生产环境。我使用capistrano(2.12.0)和rvm-capistrano(1.2.2)。当我调用bundleexeccapssh时,它工作正常。但是当我调用bundleexeccapdeploy时,我得到以下跟踪:$capdeploytriggeringstartcallbacksfor`deploy'*18:42:19==Currentlyexecuting`multistage:ensure'***Defaultingto`preprod'*18:42:19==Currentlyexecuting`preprod'*

ruby - 时间 :Class after requiring active_support/time_with_zone 的未定义方法 `zone`

我在使用Ruby2.2.1并安装了active_support4.2,所以我想使用Time.zone.parse('2007-02-1015:30:45')如此处所述:http://api.rubyonrails.org/classes/ActiveSupport/TimeWithZone.html但即使在需要active_support和active_support/time_with_zone之后,我觉得Time.zone仍然不起作用。观察:2.2.1:002>require"active_support"=>true2.2.1:003>Time.zoneNoMethodError

ruby - 为什么是 "wrong to require rubygems"?

根据thispost,需要ruby​​gems是一种反模式。require'rubygems'争论似乎归结为:WhenIuseyourlibrary,deployyourapp,orrunyourtestsImaynotwanttouserubygems.Whenyourequire'rubygems'inyourcode,youremovemyabilitytomakethatdecision.Icannotunrequirerubygems,butyoucannotrequireitinthefirstplace.但是,当您创建代码库并与其他人共享代码库时,对于您“需要”的任何Ru

ruby - $:<< "." do to Ruby's require path? 是什么意思

我不明白$:的意思在Ruby中。我将Ruby升级到1.9.1,但程序无法运行。我的同学告诉我,我应该添加$:什么是$:做? 最佳答案 $:是包含构成Ruby加载路径的路径数组的变量将一个项目追加到数组的末尾.引用当前目录123|||VVV$:所以你正在将当前目录添加到Ruby的加载路径引用资料:可以在ExecutionEnvironmentVariables中找到此页面的一部分来自ThePragmaticProgrammersGuideAnarrayofstrings,whereeachstringspecifiesadirecto

ruby-on-rails - Rails 3.1 和 Ruby 1.9.3p125 : ruby-debug19 still crashes with "Symbol not found: _ruby_threadptr_data_type"

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:ruby-debugwithRuby1.9.3?我听说ruby​​1.9.3p125有解决ruby​​-debug19问题的传言,所以根据RVM站点上的说明,我重新安装了1.9.3:$rvmreinstall1.9.3--patchdebug--force-autoconf$ruby-vruby1.9.3p125(2012-02-16revision34643)[x86_64-darwin11.2.0]然后:geminstallruby-debug19将此条目添加到我的Gemfile中:gem'ruby-de

ruby - kernel_require.rb :55:in `require' : cannot load such file error

我目前使用的是Ruby1.9.3版(尽管我在使用Ruby2.0.0时遇到了同样的问题)。在Windows764位上。我正在关注“TheCucumberBook”并卡在第7.2章-“使用转换删除重复项”。我的文件夹结构如下:\cash_withdrawal\cash_withdrawal\Gemfile\cash_withdrawal\Gemfile.lock\cash_withdrawal\features\cash_withdrawal\features\cash-withdrawal.feature\cash_withdrawal\features\step_definitions

ruby - 使用 bundler ,判断 gem 是否为 "requirable"的最佳方法是什么?

在我的Gemfile中说我有group:testdogem'rspec-core',require:falseend有没有一种简单的方法可以查看test组是否已被bundle?(比如,在这种情况下,bundle可能在有或没有--withouttest的情况下被调用)。我找不到,因此我开始寻找是否需要rspec-core,并找到了一些明显的解决方案:Bundler.definition.index.search("rspec-core")#orGem.loaded_specs["rspec-core"]确定是否需要gem的最稳定的API是什么?(不尝试要求它并挽救LoadError)

ruby - 使用 Ruby `return` 时如何防止 `yield` 出现问题

正如每个Ruby程序员最终发现的那样,调用包含return语句的block或过程可能很危险,因为这可能会退出您当前的上下文:defsome_method(&_block)puts1yield#Thefollowinglinewillneverbeexecutedinthisexample#astheyieldisactuallya`yield-and-return`.puts3enddeftestsome_methoddoputs2returnendendtest#Thisprints"1\n2\n"insteadof"1\n2\n3\n"如果您想绝对确定某些代码在您调用block或过

ruby - 背包 : how to add item type to existing solution

我一直在使用动态规划的这种变体来解决背包问题:KnapsackItem=Struct.new(:name,:cost,:value)KnapsackProblem=Struct.new(:items,:max_cost)defdynamic_programming_knapsack(problem)num_items=problem.items.sizeitems=problem.itemsmax_cost=problem.max_costcost_matrix=zeros(num_items,max_cost+1)num_items.timesdo|i|(max_cost+1).ti