feat: implement ! operator for all core types with proper truthiness semantics

Add native `!` methods to Null, Object, Num, String, and List classes so that `!` works reliably on any value. Null returns `true`, all other types return `false` since they are considered truthy. Update documentation to describe the operator as returning the logical complement and add comprehensive tests for each type. Also fix the `all` method test to use a truthy string instead of expecting a runtime error.
This commit is contained in:
Bob Nystrom
2015-01-16 05:50:01 +00:00
parent 4676e87ce9
commit d3ea153a31
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