草庐IT

send_task

全部标签

ruby - send( :method_name) and method(:method_name). 调用之间有区别吗?

ruby中send和method().call有区别吗?1.send(:to_f)=>1.01.method(:to_f).call=>1.0虽然对我来说两者似乎都一样。 最佳答案 从您的角度来看,他们做同样的事情。但是带有method的版本要慢得多(因为它在“幕后”做了更多的事情,比如创建一个方法对象)require'benchmark/ips'Benchmark.ipsdo|x|x.report('plainsend')do|times|1.send(:to_f)endx.report('methodwithcall')do|t

ruby - 在延迟的 sinatra 请求中使用 send_file

我正在尝试在异步sinatra请求期间返回一个文件,如下所示:aget"/test"doif(File.exists?("test.tar"))send_file("test.tar",:filename=>"test.tar",:type=>"application/octet-stream")returnendEM.defer(proc{#createtest.tar},proc{|r|send_file("test.tar",:filename=>"test.tar",:type=>"application/octet-stream")})然而,当我这样做时,似乎出现了错误:wr

ruby - Sinatra 中临时文件的 send_file

我正在尝试使用Sinatra的内置send_file命令,但它似乎不适用于临时文件。我基本上执行以下操作来压缩mp3专辑:get'/example'dosongs=...file_name="zip_test.zip"t=Tempfile.new(['temp_zip','.zip'])#t=File.new("testfile.zip","w")Zip::ZipOutputStream.open(t.path)do|z|songs.eachdo|song|name=song.namename+=".mp3"unlessname.end_with?(".mp3")z.put_next_

ruby-on-rails - App::Application.load_tasks 在哪里定义?

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。关闭7年前。Improvethisquestion#Addyourowntasksinfilesplacedinlib/tasksendingin.rake,#forexamplelib/tasks/capistrano.rake,andtheywillautomaticallybeavailabletoRake.requireFile.expand_path('../config/application',__FI

ruby - Travis-ci 构建失败,rake 中止!加载错误 : cannot load such file -- rspec/core/rake_task

我正在尝试将travis-ci添加到我的项目中,但它一直失败rakeaborted!LoadError:cannotloadsuchfile--rspec/core/rake_task我目前正在使用rspec3.1关于为什么会失败以及如何解决它有什么想法吗?这是我失败的项目:https://github.com/toymachiner62/readable_date_ranges/tree/tests编辑Usingworker:worker-linux-9-2.bb.travis-ci.org:travis-linux-4system_infoBuildsysteminformatio

ruby - 在类上取消定义 object_id 和 __send__ 会导致哪些严重问题?

如果我取消定义类上的所有实例方法,则会收到以下警告:warning:undefining`object_id'maycauseseriousproblemswarning:undefining`__send__'maycauseseriousproblems这可能导致的“严重问题”有哪些示例?(特别是,我也很好奇这是否对垃圾收集有任何影响?) 最佳答案 简而言之,这些方法用于元目的(例如错误报告)以及普通目的,因此它们比其他方法更重要。当出现错误时,Ruby会返回错误消息和回溯。默认情况下,一条错误消息会显示对违规对象的检查。除了一

ruby - Ruby中用 'send'调用 ':public'的意义

在Ruby中,你可以做...Object.send(:public,*Object.private_instance_methods)...如thisanswertoanotherquestion中所示.这重新定义了Object的每个私有(private)实例方法,使它们成为公共(public)的。我的问题是:这是如何工作的?send应该与方法名称一起使用,但似乎没有名为public、private或的方法在Object上定义的protected(或者至少我的搜索功能没有找到它们)。>Object.respond_to?(:public)=>false 最佳

Ruby:尝试 object.send 带有参数的模块函数

我有一个模块,其中定义了一个函数:moduleSettingsdeffind_by_name(name,start)puts"find_by_name:Foundme!"end在miniTest中,我试图以模拟它在运行时动态定义/调用的方式测试“发送”到这个函数。这是我在MiniTest中尝试做的事情。require'settings'classTestFileUtilities我期望的是send()将调用“foreign_function”方法,将字符串转换为符号,然后将两个参数添加到调用中。我想要的只是没有错误,并向我的控制台发送一个put以便我知道它正在工作......然后我将开

ruby - Windows 7 - 如何解决 “You need to have Ruby and Sass installed and in your PATH for this task to work” 警告?

大多数答案和解决方案都与OSX相关,它集中在Windows7中:我已经全局安装了Grunt&GruntCLI。然后我在项目文件夹中执行了npminstall以安装所有依赖项。到目前为止没有问题,但是当我尝试运行“gruntbuild”命令时,我在我的项目中收到了这个警告:Warning:YouneedtohaveRubyandSassinstalledandinyourPATHforthistasktowork.Moreinfo:https://github.com/gruntjs/grunt-contrib-sassUse--forcetocontinue.

ruby-on-rails - Capistrano 3,使用上传!在 lib/capistrano/tasks 的任务中

我正在使用Capistrano3,我想创建自己的任务。所以我在lib/capistrano/tasks中创建了一个文件my_new_thing.rake,当我运行cap-T时我可以看到任务。但是......有些方法不可用。当我尝试使用上传时!我明白了capaborted!NoMethodError:undefinedmethod`upload!'formain:Object但是如果我将相同的任务移动到config/deploy.rb然后再上传!方法可用。这是怎么回事?如何创建新的Capistrano任务并将它们放在单独的文件中并让它们工作? 最佳答案