Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby “expect(9).to be>6”是怎样的有效表达式?_Ruby_Rspec - Fatal编程技术网

Ruby “expect(9).to be>6”是怎样的有效表达式?

Ruby “expect(9).to be>6”是怎样的有效表达式?,ruby,rspec,Ruby,Rspec,在我的书里,我发现了一些奇怪的东西 expect(9).to be > 6 我不知道上面的表达如何有效 >怎么会这样?我搜索了rspecgithub,但没有找到任何线索。它相当于 expect(9).to(be > 6) 这相当于: expect(9).to(be.>(6)) 相当于 expect(9).to(be > 6) 这相当于: expect(9).to(be.>(6)) 在ruby中,您可以重写类上的>操作符,在本例中,RSpec::Matche

在我的书里,我发现了一些奇怪的东西

expect(9).to be > 6
我不知道上面的表达如何有效

>怎么会这样?我搜索了rspecgithub,但没有找到任何线索。

它相当于

expect(9).to(be > 6)
这相当于:

expect(9).to(be.>(6))
相当于

expect(9).to(be > 6)
这相当于:

expect(9).to(be.>(6))

在ruby中,您可以重写类上的>操作符,在本例中,RSpec::Matchers::BuiltIn::Be类是Be方法返回的


如果您想检查源代码,那么相关部分是ruby中的

,您可以重写类上的>操作符,在本例中,就是Be方法返回的RSpec::Matchers::BuiltIn::Be类


如果您想查看源代码,相关部分是

谢谢!我现在明白了。谢谢!我现在明白了。Ruby非常适合这样的表达性语句Ruby非常适合这样的表达性语句