-
-
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.
- Improved the support for autovivification.
Example: var a = []; a[0]{:foo}[1][2]{:bar}{:baz} = 42; say a; In the above example, all required hashes and arrays are automatically created, generating a structure like this: Hash("foo" => [nil, [nil, nil, Hash("bar" => Hash("baz" => 42))]])
- Loading branch information
trizen
committed
Dec 12, 2015
1 parent
7f6a0eb
commit 4455a3f
Showing
6 changed files
with
106 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/ruby | ||
|
||
# | ||
## Array | ||
# | ||
|
||
var a = []; | ||
a[0]{:foo}[1][2]{:bar}{:baz} = 42; | ||
say a; | ||
|
||
var a1 = [Hash("foo" => [nil, [nil, nil, Hash("bar" => Hash("baz" => 42))]])]; | ||
|
||
assert_eq(a, a1); | ||
assert(a[0].is_a(Hash)); | ||
assert_eq(a[0]{:foo}[1][2]{:bar}{:baz}, 42); | ||
assert_eq(a[0]{:foo}[1][2]{:bar}, Hash(baz => 42)); | ||
assert_eq(a[0]{:foo}[1][2], Hash(bar => Hash(baz => 42))); | ||
|
||
# | ||
## Hash | ||
# | ||
|
||
var b = Hash(); | ||
b{:foo}[2]{:bar}{:baz}[1][2] = 42; | ||
say b; | ||
|
||
var b1 = Hash("foo" => [nil, nil, Hash("bar" => Hash("baz" => [nil, [nil, nil, 42]]))]); | ||
|
||
assert_eq(b, b1); | ||
assert(b{:foo}.is_a(Array)); | ||
assert_eq(b{:foo}[2]{:bar}{:baz}[1][2], 42); | ||
assert_eq(b{:foo}[2]{:bar}{:baz}[1], [nil, nil, 42]); | ||
|
||
say "** Test passed!" |