草庐IT

send_command

全部标签

ruby - 将 block 添加到 Object.send 是否将其传递给被调用的方法?

我刚刚完成了RubyKoans,关于使用Object.send调用方法的单元和关于该方法的Ruby文档都没有提供任何关于将block与send方法一起使用的信息。附加到send方法的block是否会传递给它调用的方法,或者block会丢失吗?例子:foo.send(:a_method){bar.another_method} 最佳答案 documentation对此有点不清楚:send(symbol[,args...])→objInvokesthemethodidentifiedbysymbol,passingitanyargume

ruby-on-rails - rails rbenv : rails: command not found

我最近从RVM转移到Rbenv并且在尝试执行rails时出现如下错误Pauls-Air:~$railsrbenv:rails:commandnotfoundThe`rails'commandexistsintheseRubyversions:2.1.2 最佳答案 在ruby​​版本中通过命令行安装gem后,您必须按照文档here中的描述执行rbenvrehash和here例如:$rbenvinstall2.2.0$geminstallbundler$rbenvrehash$geminstallrails$rbenvrehash

ruby - Ruby 的 send 和 public_send 方法有什么区别?

我很好奇send和public_send有什么区别。例如:classKlassdefhello(*args)"Hello"+args.join('')endendk=Klass.newk.send:hello,"gentle","readers"#=>"Hellogentlereaders"k.public_send:hello,"gentle","readers"#=>"Hellogentlereaders" 最佳答案 Unlikesend,public_sendcallspublicmethodsonly.Source例子:cl

ruby - zsh : command not found: bundle (after gem install bundle)

为什么zsh:commandnotfound:bundle在geminstallbundler之后?我尝试设置path=(/usr/local/lib/ruby/gems/2.2/gems/~/bin/bin/sbin/usr/bin/usr/sbin/usr/local/bin/usr/local/sbin)在/etc/zshrc和source/etc/zshrc中无济于事。root@dev:/home/dev#geminstallbundlerSuccessfullyinstalledbundler-1.7.12Parsingdocumentationforbundler-1.7.

ruby-on-rails - 无法安装 rmagick,pkg-config : command not found

我正在尝试在我的Mac OS Xv10.9上安装rmagick(Mavericks)机器。然而。我得到这个错误/usr/local/bin/Magick-config:line41:pkg-config:commandnotfound/usr/local/bin/Magick-config:line47:pkg-config:commandnotfound/usr/local/bin/Magick-config:line50:pkg-config:commandnotfound/usr/local/bin/Magick-config:line53:pkg-config:commandn

ruby - Windows 7 中的 "ruby.exe is not recognized as an internal or external command"

我的操作系统是windows7,我正准备将我的本地MySQL数据库连接到Heroku共享数据库,有一次,我得到了libmysql.dll文件丢失的错误,所以我搜索并下载了dll文件并保存它在ruby​​/bin目录中。当我再次连接时,这次它显示错误ruby​​.exe未被识别为内部或外部命令,这就是错误的样子。发送模式'"ruby.exe"'isnotrecognizedasaninternalorexternalcommand,TA:--:--:--operableprogramorbatchfile.'"ruby.exe"'isnotrecognizedasaninternalor

ruby-on-rails - Rails 3.0 & Ruby 1.9.2rc : Rake commands return 'already initialized constant' & stack level too deep errors. 任何想法

我正在尝试在Ubuntu10.04上运行Rails3beta4和Ruby1.9.2rc。它最初有效,但在完成我的第一个bundleinstall/package之后,我现在在所有Rails项目中都遇到以下错误。即使是基本的“railsnewtestproject”后跟一个rake也会显示错误消息。简而言之,我很难过。非常感谢任何有关可能导致此问题的帮助。我唯一注意到的事情——可能相关也可能不相关——是~/.bundle文件中的目录是ruby​​/1.9.1。我的机器上没有安装1.9.1-只有1.9.2rc。ruby-v带回1.9.2(in/home/john/Websites/sand

ruby-on-rails - Rails - bundle : command not found

当我尝试在Mac上运行/检查包时遇到问题当我执行gemlist--local时,Bundler/bundler在本地gem列表中Gemenv返回以下内容RubyGemsEnvironment:-RUBYGEMSVERSION:2.0.14-RUBYVERSION:2.0.0(2014-05-08patchlevel481)[universal.x86_64-darwin14]-INSTALLATIONDIRECTORY:/Library/Ruby/Gems/2.0.0-RUBYEXECUTABLE:/System/Library/Frameworks/Ruby.framework/Ve

ruby-on-rails - 在 Ruby on Rails 中,send_file 方法后从服务器删除文件

我正在使用以下代码在Rails中发送文件。ifFile.exist?(file_path)send_file(file_path,type:'text/excel')File.delete(file_path)end在这里,我尝试发送文件并在成功发送后从服务器中删除文件。但我面临的问题是,在执行发送时删除操作正在执行,因此我在浏览器中看不到任何内容。那么在Rails中有没有什么办法,一旦send_file操作完成就从服务器上删除文件。如有任何帮助,我们将不胜感激。谢谢,切坦 最佳答案 因为您正在使用send_file,Rails会将

Ruby:如何将多个方法调用与 "send"链接在一起

必须有一种内置的方式来执行此操作,对吧?classObjectdefsend_chain(arr)o=selfarr.each{|a|o=o.send(a)}returnoendend 最佳答案 我刚刚遇到这个,它真的需要注入(inject):defsend_chain(arr)arr.inject(self){|o,a|o.send(a)}end 关于Ruby:如何将多个方法调用与"send"链接在一起,我们在StackOverflow上找到一个类似的问题: