Make all types support "!" so "if (!foo)" works reliably for all objects.

This commit is contained in:
Bob Nystrom
2015-01-15 21:50:01 -08:00
parent 94259fac8a
commit 64c2bd7633
10 changed files with 57 additions and 21 deletions
+1 -1
View File
@@ -1 +1 @@
[1, 2, 3].all {|x| "string" } // expect runtime error: String does not implement method '!' with 0 arguments.
IO.print([1, 2, 3].all {|x| "truthy" }) // expect: true
+2
View File
@@ -0,0 +1,2 @@
IO.print(![1, 2]) // expect: false
IO.print(![]) // expect: false
+1
View File
@@ -0,0 +1 @@
IO.print(!null) // expect: true
+2
View File
@@ -0,0 +1,2 @@
IO.print(!123) // expect: false
IO.print(!0) // expect: false
+2
View File
@@ -0,0 +1,2 @@
class Foo {}
IO.print(!(new Foo)) // expect: false
+2
View File
@@ -0,0 +1,2 @@
IO.print(!"s") // expect: false
IO.print(!"") // expect: false