小编Enc*_*ira的帖子

比较rspec中的浮点数时的奇怪行为

以下测试中的第3个失败:

  specify { (0.6*2).should eql(1.2) }
  specify { (0.3*3).should eql(0.3*3) }
  specify { (0.3*3).should eql(0.9) } # this one fails
Run Code Online (Sandbox Code Playgroud)

这是为什么?这是浮点问题还是ruby或rspec问题?

ruby floating-point rspec

5
推荐指数
2
解决办法
1714
查看次数

如何在Swift中将元组转换为AnyObject

以下代码编译错误: Error:(112, 20) type '(String, Int)' does not conform to protocol 'AnyObject'

func myMethode() {
    aMethodeThatICanNotChange {
        let a  = ("John",7)
        return a  // Error:(112, 20) type '(String, Int)' does not conform to protocol 'AnyObject'
    }
}

func aMethodeThatICanNotChange(closure: () -> AnyObject) {
     // do something with closure
}
Run Code Online (Sandbox Code Playgroud)

如何将元组转换/转换为AnyObject?

tuples swift

4
推荐指数
2
解决办法
2962
查看次数

标签 统计

floating-point ×1

rspec ×1

ruby ×1

swift ×1

tuples ×1