草庐IT

where-is-the-game-loop-t

全部标签

ruby 管道 : How do I tie the output of two subprocesses together?

在Ruby中是否有自动执行shell管道的方法?我正在尝试将以下shell代码转换为Ruby:a|b|c...>...但到目前为止我找到的唯一解决方案是自己进行缓冲区管理(经过简化,未经测试,希望它能理解我的意思):a=IO.popen('a')b=IO.popen('b','w+')Thread.new(a,b){|in,out|out.write(in.readpartial(4096))untilin.eof?out.close_write}#dealwithb.read...我想我正在寻找的是一种告诉popen使用现有流而不是创建新流的方法?或者,将a的输出连接到b的输入的IO

ruby-on-rails - rbenv : version `2.0.0' is not installed

我正在尝试使用Bundleinstall安装Gemfile内容,但出现错误rbenv:version`2.0.0'isnotinstalled我系统安装的ruby版本是:ruby2.1.2p95(2014-05-08revision45877)[i686-linux]和rbenv2.1.2(setby/home/jay/.rbenv/version)2.1.3Gemfile需要ruby"2.0.0"。谁能告诉我如何在不影响现有版本的情况下安装所需的版本。 最佳答案 您可以在这里找到很多信息:rbenvongithub列出所有可用的安

ruby-on-rails - rails : Copying attributes from an object to another using the "attributes" method

让模型Quote具有属性[price,description]让模型Invoice有属性[price,description,priority]让invoice模型Invoice中的对象具有属性{price:10,description:'lamp',priority:10}invoice={price:10,description:'lamp',priority:10}假设我想将invoice属性复制到新的quote。quote=Quote.new(invoice.attributes)这会引发一个错误,即priority在模型Quote中不存在。如何将invoice属性复制到新的q

ruby - 获取名称错误 : `format' is not allowed as an instance variable name when testing instance variable with rspec

我有以下测试:let(:client){Descat::Client.new}describe'poblacio'doit'shouldsetformatcorrectly'doclient.poblacio('v1','json','dades')expect(client.instance_variable_get(:format)).toeq('json')endend我有以下正在测试的代码:moduleDescatclassClientBASE_URL='http://api.idescat.cat/'definitialize(attributes={})attributes

ruby - 我在 Mac OS X 上收到 "RVM is not a function"错误,并且没有发布的解决方案有效

我在MacOSx10.8.2(“MountainLion”)上,我成功安装了RVM1.17.8及其依赖项。我可以使用它来使用rvminstall1.9.2安装Ruby版本,但我无法执行rvmuse没有收到此错误:RVMisnotafunction,selectingrubieswith'rvmuse...'willnotwork.Youneedtochangeyourterminalemulatorpreferencestoallowloginshell.Sometimesitisrequiredtouse`/bin/bash--login`asthecommand.Pleasevis

ruby 摩卡 : is there an equivalent to rspec-mocks' #and_call_original?

Rspec-mocks具有expect(some_object).toreceive(:some_method).and_call_original。我可以用Mocha做这个吗?如果可以,怎么做?some_object.expects(:some_method).......什么? 最佳答案 我相当确定没有办法做到这一点。浏览sourcecode,有评论提到完全替换了原来的方法。#Theoriginalimplementationofthemethodisreplacedduringthetestandthenrestoredatt

ruby - sinatra config.ru : what is the configure block for?

我将Sinatra与Apache和“经典”风格的Phusion-Passenger一起使用:#config.rurequire'sinatra'configuredo....endrequire'./app'runSinatra::Application我想定义一些东西。在配置block内部或外部定义它有什么区别?#config.rurequire'sinatra'#A)Definingloggerhererack=File.new("logs/rack.log","a+")useRack::CommonLogger,rack#B)GlobalvariableshereLOGGER=L

ruby-on-rails - Rails 中的命名空间模型 : What's the state of the union?

从一开始,Rails就存在命名空间模型的问题。随着时间的推移,几乎每个人都放弃了使用它。包括我自己。随着Rails2.3的发布,我想了解最新情况。我想到的具体问题是:首先,可以出发了吗?表的命名,有什么规律可循?协会,如何以最不冗长的方式声明它们?如何命名外键列?自动请求,如果将模型文件放在与命名空间匹配的子目录中,它会起作用吗?或者,如何命名和放置文件?代,模型生成器是否成功并正确地处理命名空间?生成器,包含Controller的脚手架生成器怎么样?任何应该注意的不兼容性/怪癖? 最佳答案 我见过的关于这个问题的最好的文章来自St

ruby-on-rails - rails : Your user account isn't allowed to install to the system RubyGems

我正在运行命令bundleinstall在项目文件夹中。在某些项目文件夹中,它会产生错误,而在其他项目文件夹中,它不会产生错误。错误是:Youruseraccountisn'tallowedtoinstalltothesystemRubyGems我知道这可以通过遵循推荐的建议来解决:bundleinstall--pathvendor/bundle我的问题是为什么行为不一致? 最佳答案 在我的例子中,我按照错误消息的建议解决了问题:Youruseraccountisn'tallowedtoinstalltothesystemRubyG

ruby-on-rails - ruby rails : How do you check if a file is an image?

如何检查文件是否为图像?我想你可以使用这样的方法:defimage?(file)file.to_s.include?(".gif")orfile.to_s.include?(".png")orfile.to_s.include?(".jpg")end但这可能有点低效而且不正确。有什么想法吗?(我正在使用回形针插件,顺便说一句,但我没有看到任何方法来确定文件是否是回形针中的图像) 最佳答案 请检查一次MIME::Types.type_for('tmp/img1.jpg').first.try(:media_type)=>"image"