草庐IT

imap-send

全部标签

ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法?

类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

ruby - 为什么人们使用 `Module.send(:prepend, …)` ?

我正在学习如何在我的Ruby代码中使用Module.prepend而不是alias_method_chain,我注意到有些人使用send调用它(example):ActionView::TemplateRenderer.send(:prepend,ActionViewTemplateRendererWithCurrentTemplate)而其他人直接调用它(example):ActionView::TemplateRenderer.prepend(ActionViewTemplateRendererWithCurrentTemplate)而且,虽然我还没有看到任何人使用这种风格,但我从

ruby - 使用 `+=` 和 `send` 方法

如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:

ruby - Ruby 的 AST 中的 'send' 关键字是什么意思?

我正在尝试学习Ruby词法分析器和解析器(whitequarkparser)以了解更多有关从Ruby脚本进一步生成机器代码的过程。在解析以下Ruby代码字符串时。defadd(a,b)returna+bendputsadd1,2它导致以下S表达式符号。s(:begin,s(:def,:add,s(:args,s(:arg,:a),s(:arg,:b)),s(:return,s(:send,s(:lvar,:a),:+,s(:lvar,:b)))),s(:send,nil,:puts,s(:send,nil,:add,s(:int,1),s(:int,3))))任何人都可以向我解释生成的

Ruby:如何使用带有散列的 'send' 方法调用方法?

假设我有一个类A,里面有一些方法。假设stringmethodName是这些方法之一,我已经知道我想给它什么参数。它们在散列中{'param1'=>value1,'param2'=>value2}所以我有:params={'param1'=>value1,'param2'=>value2}a=A.new()a.send(methodName,value1,value2)#callmethodnamewithbothparams我希望能够通过传递我的哈希以某种方式调用该方法。这可能吗? 最佳答案 确保methodName是一个符号,而

Ruby/Sinatra send_file 不工作

我在Sinatra应用程序上使用send_file:get'/update/dl/:upd'dofilename="/uploads/#{params[:upd]}"send_file(filename,:filename=>"t.cer",:type=>"application/octet-stream")end/uploads/文件夹不是公开的,它在应用程序目录中。当我尝试在Chrome中访问localhost:4567/update/dl/some_file时,它会返回404,就像在Firefox中一样,当看到标题时,它是404。但是如果我尝试使用Safari,它下载文件。所以我

ruby-on-rails - Rails 使用 send_data 或 send_file 将多个文件发送到浏览器

我正在尝试向浏览器发送多个文件。我不能像下面的代码一样为每条记录调用send_data,因为我收到双重渲染错误。根据thispost我需要创建文件并压缩它们,以便我可以在一个请求中发送它们。@records.eachdo|r|ActiveRecord::Base.include_root_in_json=true@json=r.to_jsona=ActiveSupport::MessageEncryptor.new(Rails.application.config.secret_token)@json_encrypted=a.encrypt_and_sign(@json)send_da

ruby - 如何使用 ruby​​ `net/imap` 归档消息

使用以下ruby​​代码,我可以通过IMAP阅读收件箱中用户的邮件:require'net/imap'imap=Net::IMAP.new('imap.gmail.com',993,true)imap.login('user','passwd')imap.select('INBOX')mailIds=imap.search(['ALL'])mailIds.eachdo|id|msg=imap.fetch(id,'RFC822')[0].attr['RFC822']putsmsgendimap.logout()imap.disconnect()我想知道如何存档和标记已读电子邮件。我想将电

ruby-on-rails - 使用 rails send_data 发送 PDF

我使用ruby​​1.9.3和redmine1.4.4据此->Pleasehelpmesendajpgfileusingsend_data,我在Controller中这样做:@file=temp.pathFile.open(@file,'r')do|f|send_dataf.read,:filename=>"myfile.pdf",:type=>"application/pdf",:disposition=>"attachment"endFile.delete(@file)但它返回ArgumentError(UTF-8中的无效字节序列),为什么? 最佳答案

ruby-on-rails - 通过 IMAP 在 Rails 中获取电子邮件

我有一个在本地Intranet上运行的Rails应用程序,有1000个常规用户。我希望将它与我们的电子邮件服务器(MSExchange)集成。基本上-1)对于每个用户,应用程序应从邮件服务器获取其收件箱中的所有新邮件,对其进行解析,并将其归档到数据库中。我可以用ruby​​/net-imap实现它,但我担心性能。正如我所提到的,有一千个用户,每个用户都有不同的电子邮件地址。每x分钟轮询一次电子邮件服务器对于一千个用户来说会大大降低性能。看起来像IMAPIDLEwithruby/net-imap可能是一个选项,只要有新邮件(iPhone/Outlook样式),邮件服务器就会向我的应用程序