-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Simplified and generalized the support for local variables.
They can now localize entire expressions, instead of only strict variable names. Example: local hash{:key} = 42; # localize an element inside an hash However, for the sake of simplicity, local variable no longer can declare new variables. Example: local new_var = "foo"; # "new_var" is declared as a global variable (with a warning)
- Loading branch information
trizen
committed
Nov 1, 2015
1 parent
11e952b
commit 4409629
Showing
11 changed files
with
59 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/ruby | ||
|
||
# | ||
## Test 1 | ||
# | ||
|
||
class Example { | ||
method foo(arg) { | ||
assert_eq(self{:bar}, arg); | ||
} | ||
} | ||
|
||
var obj = Example(); | ||
|
||
obj{:bar} = 21; # add some value inside the object | ||
obj.foo(21); # call the method foo | ||
|
||
do { | ||
local obj{:bar} = 42; # localize the value of 'bar' to 42 | ||
obj.foo(42); # call the method foo | ||
assert_eq(obj{:bar}, 42); | ||
} | ||
|
||
obj.foo(21); # the value of bar is unlocalized here | ||
assert_eq(obj{:bar}, 21); # test again to be sure | ||
|
||
|
||
# | ||
## Test 2 | ||
# | ||
|
||
global x = 42; | ||
|
||
do { | ||
assert_eq(x, 42); | ||
local x = 100; | ||
assert_eq(x, 100); | ||
} | ||
|
||
assert_eq(x, 42); | ||
|
||
|
||
say "** Test passed!"; |