It turns out "is" is just a normal overridable operator. Who knew?

This commit is contained in:
Bob Nystrom
2015-11-07 13:00:24 -08:00
parent 931d9ca4d3
commit 7ae9888c4f
5 changed files with 30 additions and 4 deletions
+8 -1
View File
@@ -123,7 +123,7 @@ We also have a slew of infix operators—they have operands on both sides.
They are:
:::wren
== != < > <= >= .. ... | & + - * / %
== != < > <= >= .. ... | & + - * / % is
Like prefix operators, they are all funny ways of writing method calls. The left
operand is the receiver, and the right operand gets passed to it. So `a + b` is
@@ -138,6 +138,13 @@ objects, but they are method calls like other operators.
[range]: values.html#ranges
The `is` keyword is a "type test" operator. The base [Object][] class implements
it to tell if an object is an instance of a given class. You'll rarely need to,
but you can override `is` in your own classes. That can be useful for things
like mocks or proxies where you want an object to masquerade as a certain class.
[object]: core/object.html
## Subscripts
Another familiar syntax from math class is *subscripting* using square brackets