草庐IT

el4r-instance

全部标签

ruby-on-rails - XMPP4r - 无法检索离线消息

我正在尝试使用带有openfire服务器的ruby​​xmpp4r库获取openfire多用户群聊天历史记录。我可以构建请求,但没有收到服务器回复。下面是发现请求iqr=Iq.new(:get,"example.com")iqr.add_namespace("http://jabber.org/protocol/disco#info")client.send(iqr)这是请求的框架但我没有收到服务器回复。我关注了XEP-0160和XEP-0013。我在这里错过了什么?openfire是否提供房间聊天记录?有相应的API吗?非常感谢任何帮助。而且我不太了解openfire,因此非常感谢有

ruby-on-rails - RSpec::Mocks::ExampleMethods 的未定义方法 instance_double

我有一个这样的测试用例:describeWorkCardsControllerdoit"something"dowork_card=instance_double(WorkCard,{:started?=>true})#somemorecodeendend当我运行RSpec时,出现错误:undefinedmethod'instance_double'for#根据http://rubydoc.info/github/rspec/rspec-mocks/RSpec/Mocks/ExampleMethods这种方法存在。所以我尝试通过以下方式直接访问它:describeWorkCardsCo

ruby - 可能对 curry 过程进行 instance_eval 吗?

假设我有这样一个类:classTestdeftest_func140endend还有一个proc,它引用了Test中的一个成员函数:p=->(x,y){x+y+test_func}#=>#要调用p,我将它绑定(bind)到Test的一个实例:test=Test.new#=>#test.instance_exec(1,2,&p)#=>143现在假设我只想将y传递给p,并且始终传递x=1:curried=p.curry[1]#=>#理想情况下,我应该能够像以前一样instance_exec,但是:test.instance_exec(2,&curried)=>NameError:undef

ruby - 我可以将一个本身需要一个 block 的 block 传递给 ruby​​ 中的 instance_exec 吗?

我期待代码foo=proc{puts"foo"}instance_exec(1,2,3,&foo)do|*args,&block|puts*argsblock.callputs"bar"end输出123foobar但是报错bothblockargandactualblockgiven我可以将一个本身需要一个block的block传递给ruby​​中的instance_exec吗? 最佳答案 &foo尝试将foo作为block传递给instance_exec,而您已经传递了一个显式block。省略与号发送foo就像任何其他参数一样(除

ruby - 模块嵌套在 instance_eval/exec 或 module_eval/exec 中

我在尝试回答this时想到了这个问题.以下是预期的行为:moduleApModule.nestingend#=>[A]但是以下内容:A.instance_eval{pModule.nesting}A.instance_exec{pModule.nesting}A.module_eval{pModule.nesting}A.module_exec{pModule.nesting}全部返回[]。为什么这些不能像上面那样工作?附加问题Muistooshort提出了一个有趣的观点。如果这是正确的,那么Module.nesting将是依赖于文字上下文的方法和变量之一,例如Method#sourc

ruby - 如何像 instance_eval 方法那样在一个 block 中改变 self 呢?

instance_eval方法在其block中改变自身,例如:classD;endd=D.newd.instance_evaldoputsself#printsomethinglike#,not'main'!end如果我们自己定义一个方法(或任何其他方法(除了instance_eval)需要一个block),当打印self时,我们将得到'main',这与instance_eval方法不同。例如:[1].eachdo|e|putsself#print'main'end我如何定义一个像instance_eval这样的方法(需要一个block)?提前致谢。 最佳答

ruby - gem install rmagick 在 OS X El Capitan 上失败

几天前我升级到ElCapitan并运行了一个brewupdate&&brewupgrade它更新了imagemagick,导致ruby​​的rmagickgem停止工作。我想没问题,我就跑geminstallrmagick它会重新编译。除了没有,当我运行它时我看到了这个:geminstallrmagickBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingrmagick:ERROR:Failedtobuildgemnativeextension./Users/sam/.rbenv/versions/2.

ruby - 传递给 `instance_exec` 时如何执行 proc

问题的灵感来自thisone.Proc::new有一个选项可以在方法内部没有block的情况下调用:Proc::newmaybecalledwithoutablockonlywithinamethodwithanattachedblock,inwhichcasethatblockisconvertedtotheProcobject.当proc/lambda实例作为代码块传递时,将创建Proc的新实例:Proc.singleton_class.prepend(Module.newdodefnew(*args,&cb)puts"PROC#{[block_given?,cb,*args].i

ruby-on-rails - 安装 "nio4r": Failed to build gem native extension 时的 rails 5.0.0

这是日志:http://pastebin.com/CAgur9xdInstallingnio4r1.2.1withnativeextensionsGem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension.C:/RailsInstaller/Ruby2.2.0/bin/ruby.exe-r./siteconf20160720-8272-c88sgk.rbextconf.rb--with-cflags=-std=c99checkingforunistd.h...***extconf.rbfailed***Couldnotcreat

ruby : how to prevent modification of an array instance variable through an attribute reader

抱歉这个菜鸟问题...假设我们有:classTestMeattr_reader:arraydefinitialize@array=(1..10).to_aend结束然后可以这样做:>>a=TestMe.new=>#>>a.array.map!&:to_s=>["1","2","3","4","5","6","7","8","9","10"]>>a.array=>["1","2","3","4","5","6","7","8","9","10"]这显然不利于封装,不是吗?有什么方法可以快速保护数组变量不被更改吗?...或者每当我的实例变量具有“破坏性”方法时,我是否需要实现一个深拷贝读取