refactor: convert IO from singleton instance to static class with metaclass native methods

Replace the global `io` singleton object with a static `IO` class, moving the `write` native from the instance to the metaclass. Update all benchmark, example, and test files to use `IO.write()` instead of `io.write()`.
This commit is contained in:
Bob Nystrom
2013-12-22 03:25:09 +00:00
parent 1a77a43fa0
commit 8bb1a94a25
119 changed files with 532 additions and 536 deletions
+9 -9
View File
@@ -1,32 +1,32 @@
var a = [1, 2, 3]
a.removeAt(0)
io.write(a) // expect: [2, 3]
IO.write(a) // expect: [2, 3]
var b = [1, 2, 3]
b.removeAt(1)
io.write(b) // expect: [1, 3]
IO.write(b) // expect: [1, 3]
var c = [1, 2, 3]
c.removeAt(2)
io.write(c) // expect: [1, 2]
IO.write(c) // expect: [1, 2]
// Index backwards from end.
var d = [1, 2, 3]
d.removeAt(-3)
io.write(d) // expect: [2, 3]
IO.write(d) // expect: [2, 3]
var e = [1, 2, 3]
e.removeAt(-2)
io.write(e) // expect: [1, 3]
IO.write(e) // expect: [1, 3]
var f = [1, 2, 3]
f.removeAt(-1)
io.write(f) // expect: [1, 2]
IO.write(f) // expect: [1, 2]
// Out of bounds.
// TODO: Signal error in better way.
io.write([1, 2, 3].removeAt(3)) // expect: null
io.write([1, 2, 3].removeAt(-4)) // expect: null
IO.write([1, 2, 3].removeAt(3)) // expect: null
IO.write([1, 2, 3].removeAt(-4)) // expect: null
// Return the removed value.
io.write([3, 4, 5].removeAt(1)) // expect: 4
IO.write([3, 4, 5].removeAt(1)) // expect: 4