我有点困惑为什么我的项目无法加载它需要的文件,这是一个非常简单的项目树:
processor/
bin/
lib/
processor.rb
processor/
mapper.rb
reducer.rb
Run Code Online (Sandbox Code Playgroud)
我的processor.rb文件看起来像
require 'processor/mapper'
require 'processor/reducer'
class Processor
end
Run Code Online (Sandbox Code Playgroud)
只是为了测试文件映射器看起来像:
class Mapper
def run
puts "running map"
end
end
Run Code Online (Sandbox Code Playgroud)
但运行ruby lib/processor.rb结果:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- processor/mapper (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from lib/processor.rb:3:in `<class:Processor>'
from lib/processor.rb:2:in `<main>'
Run Code Online (Sandbox Code Playgroud) 在Ruby中,有人告诉我这样做
require "some_file"
Run Code Online (Sandbox Code Playgroud)
Ruby将在某些地方查找该文件.
我知道它在寻找some_file.rb,但默认情况下它在哪里寻找?
我有兴趣设置一个监控服务,只要在Resque队列中有太多的工作就会给我发信息(我有大约6个队列,每个队列都有不同的编号).我还想设置一个非常相似的监控服务,当我在队列中超过一定数量的失败作业时,它会提醒我.
我的问题是,我在redis服务器上看到与Resque有关的密钥和混乱.我不一定能看到一种直接的方法来获得每个队列的作业数或失败的作业数.目前有一种从redis获取此数据的简单方法吗?
我正在寻找一种更好的方法
if hash.key? :a &&
hash.key? :b &&
hash.key? :c &&
hash.key? :d
Run Code Online (Sandbox Code Playgroud)
最喜欢的东西
hash.includes_keys? [ :a, :b, :c, :d ]
Run Code Online (Sandbox Code Playgroud)
我想出来了
hash.keys & [:a, :b, :c, :d] == [:a, :b, :c, :d]
Run Code Online (Sandbox Code Playgroud)
但我不喜欢两次添加数组
我的gemfile中有以下行:
gem 'client_side_validations', :git => "git@github.com:Dakuan/client_side_validations.git", :branch => "master", ref: '2245b4174ffd4b400d999cb5a2b6dccc0289eb67'
Run Code Online (Sandbox Code Playgroud)
它指向的repo是公共的,我可以在本地运行bundle install/update就好了.当我尝试推送到Heroku时,我收到以下错误:
Run Code Online (Sandbox Code Playgroud)Fetching git@github.com:Dakuan/client_side_validations.git Host key verification failed. fatal: The remote end hung up unexpectedly Git error: command `git clone 'git@github.com:Dakuan/client_side_validations.git' "/tmp/build_1xa9f06n4k1cu/vendor/bundle/ruby/1.9.1/cache/bundler/git/client_side_validations-56a04875baabb67b5f8c192c6c6743df476fd90f" --bare --no-hardlinks` in directory /tmp/build_1xa9f06n4k1cu has failed.!!无法通过Bundler安装gem.!!Heroku推送拒绝,无法编译Ruby/rails应用程序
有人对这里发生的事情有任何想法吗?
我在一个旧的Rails项目中有一个Gemfile.我试图在Gemfile中添加一个gem,bundle install但是出现了错误:
Bundler could not find compatible versions for gem "bundler":
In Gemfile:
rails (= 3.0.0) ruby depends on
bundler (~> 1.0.0) ruby
Current Bundler version:
bundler (1.1.5)
This Gemfile requires a different version of Bundler.
Run Code Online (Sandbox Code Playgroud)
它使用的Rails版本需要捆绑器〜> 1.0.0但我安装了1.1.5并且正在将其用于我的其他项目.通常我会使用,bundle exec ...但因为这是我们所说的捆绑器,它比这复杂一点.如何在我的Gemfile中添加gem并bundle install在使用它所需的Bundler 版本时运行?
我对ruby很新(我实际上是c#dev.),所以这个问题可能是一个菜鸟.我有一个像下面这样的类,我使用实例变量(数组)来避免使用大量的方法参数.
它按照我的预期工作,但这是一个很好的做法吗?实际上我不希望它有效,但我想类方法在其他语言中不能作为静态方法工作,所以我想知道这是不是一个好的做法,或者我是否会遇到诸如将这些变量作为类变量和乱码的问题一切都好了.
class DummyClass
def self.dummy_method1
@arr = []
# Play with that array
end
def self.dummy_method2
# use @arr for something else
end
end
Run Code Online (Sandbox Code Playgroud) 对于Array,有一种很好的sort方法来重新排列元素序列.我想为String实现相同的结果.
例如,我有一个字符串str = "String",我想用一个简单的方法按字母顺序对它进行排序"ginrSt".
是否有本地方式来启用此功能,还是应该包含mixins Enumerable?
我正在测试一些从环境变量中提取配置的代码(由生产中的Heroku配置变量设置,我使用工头进行本地开发).
使用RSpec测试此类代码的最佳方法是什么?
我想出了这个:
before :each do
ENV.stub(:[]).with("AWS_ACCESS_KEY_ID").and_return("asdf")
ENV.stub(:[]).with("AWS_SECRET_ACCESS_KEY").and_return("secret")
end
Run Code Online (Sandbox Code Playgroud)
如果您不需要测试环境变量的不同值,我猜您可以设置它们spec_helper.
我知道如何在Ruby中运行shell命令,如:
%x[#{cmd}]
Run Code Online (Sandbox Code Playgroud)
但是,如何指定运行此命令的目录?
是否有类似于shell的方式,类似于subprocess.PopenPython:
subprocess.Popen(r'c:\mytool\tool.exe', cwd=r'd:\test\local')
Run Code Online (Sandbox Code Playgroud)
谢谢!