standalone @ and @@ are aliases for self and self.__class

This commit is contained in:
leaf corcoran 2012-01-10 22:14:14 -08:00
parent 3a2b92e5d3
commit d7f8ade88e
3 changed files with 35 additions and 1 deletions

View File

@ -864,6 +864,23 @@ described above:
These expressions are executed after all the properties have been added to the
*base*.
### `@` and `@@` Values
When `@` and `@@` are prefixed in front of a name they represent, respectively,
that name accessed in `self` and `self.__class`.
If they are used all by themselves, they are aliases for `self` and
`self.__class`.
assert @ == self
assert @@ == self.__class
For example, a quick way to create a new instance of the same class from an
instance method using `@@`:
some_instance_method = (...) => @@ ...
## Export Statement
Because, by default, all assignments to variables that are not lexically visible will

View File

@ -266,7 +266,10 @@ local build_grammar = wrap_env(function()
return true
end) / trim
local SelfName = Space * "@" * ("@" * _Name / mark"self_class" + _Name / mark"self")
local SelfName = Space * "@" * (
"@" * (_Name / mark"self_class" + Cc"self.__class") +
_Name / mark"self" + Cc"self")
local KeyName = SelfName + Space * _Name
local Name = SelfName + Name + Space * "..." / trim

View File

@ -101,3 +101,17 @@ class ClassMan
@red: =>
x = @
y = @@
@ something
@@ something
@ = @ + @ / @
@ = 343
@.hello 2,3,4
hello[@].world