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:
@@ -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
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
IO.print(![1, 2]) // expect: false
|
||||
IO.print(![]) // expect: false
|
||||
@@ -0,0 +1 @@
|
||||
IO.print(!null) // expect: true
|
||||
@@ -0,0 +1,2 @@
|
||||
IO.print(!123) // expect: false
|
||||
IO.print(!0) // expect: false
|
||||
@@ -0,0 +1,2 @@
|
||||
class Foo {}
|
||||
IO.print(!(new Foo)) // expect: false
|
||||
@@ -0,0 +1,2 @@
|
||||
IO.print(!"s") // expect: false
|
||||
IO.print(!"") // expect: false
|
||||
Reference in New Issue
Block a user