fancy 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +14 -14
- data/Rakefile +16 -4
- data/bin/fancy +3 -0
- data/bin/fspec +20 -0
- data/bin/fyi +27 -11
- data/bin/ifancy +1 -1
- data/boot/fancy_ext.rb +1 -0
- data/boot/fancy_ext/block_env.rb +1 -9
- data/boot/fancy_ext/delegator.rb +64 -0
- data/boot/fancy_ext/object.rb +4 -0
- data/boot/fancy_ext/thread.rb +4 -0
- data/boot/load.rb +5 -1
- data/boot/rbx-compiler/compiler/ast.rb +0 -1
- data/boot/rbx-compiler/compiler/ast/class_def.rb +2 -0
- data/boot/rbx-compiler/compiler/ast/method_def.rb +2 -0
- data/boot/rbx-compiler/compiler/ast/node.rb +10 -0
- data/boot/rbx-compiler/compiler/ast/ruby_args.rb +12 -0
- data/boot/rbx-compiler/compiler/ast/singleton_method_def.rb +2 -0
- data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
- data/boot/rbx-compiler/parser/lexer.lex +5 -11
- data/boot/rbx-compiler/parser/parser.rb +16 -5
- data/boot/rbx-compiler/parser/parser.y +39 -24
- data/doc/api/fancy.css +1 -1
- data/doc/api/fancy.jsonp +1 -1
- data/doc/api/fdoc.js +22 -4
- data/doc/api/index.html +5 -6
- data/doc/api/jquery-ui.min.js +401 -0
- data/doc/api/jquery.tools.min.js +192 -0
- data/doc/api/themeswitchertool.js +250 -0
- data/doc/features.md +17 -0
- data/examples/actor_bunnies.fy +32 -0
- data/examples/actors.fy +26 -0
- data/examples/actors_primitive.fy +27 -0
- data/examples/actors_ring.fy +37 -0
- data/examples/armstrong_numbers.fy +1 -1
- data/examples/array.fy +7 -9
- data/examples/async_send.fy +1 -2
- data/examples/blocks.fy +4 -4
- data/examples/call_with_receiver.fy +1 -1
- data/examples/class.fy +1 -1
- data/examples/default_args.fy +4 -1
- data/examples/define_methods.fy +2 -2
- data/examples/echo.fy +1 -1
- data/examples/factorial.fy +1 -1
- data/examples/future_composition.fy +2 -2
- data/examples/futures.fy +0 -5
- data/examples/game_of_life.fy +1 -1
- data/examples/person.fy +1 -1
- data/lib/argv.fy +7 -2
- data/lib/array.fy +109 -42
- data/lib/block.fy +39 -14
- data/lib/boot.fy +2 -0
- data/lib/class.fy +2 -0
- data/lib/compiler/ast.fy +2 -1
- data/lib/compiler/ast/assign.fy +2 -3
- data/lib/compiler/ast/async_send.fy +1 -15
- data/lib/compiler/ast/class_def.fy +2 -1
- data/lib/compiler/ast/expression_list.fy +4 -5
- data/lib/compiler/ast/future_send.fy +1 -10
- data/lib/compiler/ast/goto.fy +46 -0
- data/lib/compiler/ast/identifier.fy +9 -7
- data/lib/compiler/ast/literals.fy +8 -1
- data/lib/compiler/ast/match.fy +14 -4
- data/lib/compiler/ast/message_send.fy +34 -6
- data/lib/compiler/ast/method_def.fy +6 -6
- data/lib/compiler/ast/node.fy +3 -3
- data/lib/compiler/ast/range.fy +1 -0
- data/lib/compiler/ast/script.fy +0 -2
- data/lib/compiler/ast/singleton_method_def.fy +2 -4
- data/lib/compiler/ast/string_interpolation.fy +17 -0
- data/lib/compiler/ast/super.fy +5 -4
- data/lib/compiler/ast/try_catch.fy +8 -6
- data/lib/compiler/ast/tuple_literal.fy +3 -2
- data/lib/compiler/command.fy +0 -1
- data/lib/compiler/compiler.fy +1 -5
- data/lib/compiler/stages.fy +6 -14
- data/lib/documentation.fy +57 -46
- data/lib/enumerable.fy +257 -23
- data/lib/enumerator.fy +122 -15
- data/lib/false_class.fy +10 -1
- data/lib/fancy_spec.fy +263 -61
- data/lib/fdoc.fy +11 -25
- data/lib/fiber.fy +11 -0
- data/lib/file.fy +8 -11
- data/lib/future.fy +84 -5
- data/lib/hash.fy +65 -14
- data/lib/integer.fy +35 -0
- data/lib/iteration.fy +54 -29
- data/lib/message.fy +6 -0
- data/lib/method.fy +0 -16
- data/lib/nil_class.fy +58 -8
- data/lib/number.fy +49 -22
- data/lib/object.fy +371 -65
- data/lib/package.fy +24 -1
- data/lib/package/installer.fy +5 -9
- data/lib/package/specification.fy +2 -2
- data/lib/parser/ext/lexer.lex +15 -11
- data/lib/parser/ext/parser.y +70 -23
- data/lib/parser/methods.fy +33 -14
- data/lib/proxy.fy +33 -3
- data/lib/range.fy +28 -0
- data/lib/rbx.fy +3 -1
- data/lib/rbx/actor.fy +53 -0
- data/lib/rbx/alpha.fy +31 -0
- data/lib/rbx/array.fy +21 -12
- data/lib/rbx/bignum.fy +6 -2
- data/lib/rbx/block.fy +23 -26
- data/lib/rbx/class.fy +54 -2
- data/lib/rbx/code_loader.fy +8 -4
- data/lib/rbx/date.fy +9 -0
- data/lib/rbx/directory.fy +18 -0
- data/lib/rbx/environment_variables.fy +1 -0
- data/lib/rbx/exception.fy +9 -2
- data/lib/rbx/fiber.fy +22 -4
- data/lib/rbx/file.fy +5 -5
- data/lib/rbx/fixnum.fy +5 -0
- data/lib/rbx/float.fy +11 -3
- data/lib/rbx/hash.fy +31 -16
- data/lib/rbx/integer.fy +1 -0
- data/lib/rbx/io.fy +17 -7
- data/lib/rbx/match_data.fy +15 -4
- data/lib/rbx/method.fy +40 -7
- data/lib/rbx/name_error.fy +4 -0
- data/lib/rbx/object.fy +92 -24
- data/lib/rbx/range.fy +20 -6
- data/lib/rbx/regexp.fy +11 -3
- data/lib/rbx/string.fy +51 -1
- data/lib/rbx/stringio.fy +17 -0
- data/lib/rbx/symbol.fy +15 -1
- data/lib/rbx/system.fy +20 -2
- data/lib/rbx/tcp_server.fy +4 -1
- data/lib/rbx/tcp_socket.fy +11 -0
- data/lib/rbx/time.fy +6 -0
- data/lib/rbx/tuple.fy +14 -5
- data/lib/set.fy +144 -29
- data/lib/stack.fy +42 -11
- data/lib/string.fy +118 -8
- data/lib/struct.fy +13 -3
- data/lib/symbol.fy +21 -2
- data/lib/thread_pool.fy +2 -1
- data/lib/true_class.fy +45 -7
- data/lib/tuple.fy +27 -9
- data/lib/version.fy +2 -2
- data/ruby_lib/fancy +43 -0
- data/ruby_lib/fdoc +23 -0
- data/ruby_lib/fspec +3 -0
- data/ruby_lib/fyi +3 -0
- data/ruby_lib/ifancy +3 -0
- data/tests/argv.fy +5 -9
- data/tests/array.fy +323 -196
- data/tests/assignment.fy +29 -29
- data/tests/block.fy +72 -59
- data/tests/class.fy +227 -138
- data/tests/control_flow.fy +83 -51
- data/tests/documentation.fy +8 -8
- data/tests/enumerable.fy +8 -0
- data/tests/enumerator.fy +47 -29
- data/tests/exception.fy +49 -32
- data/tests/file.fy +28 -28
- data/tests/fixnum.fy +170 -0
- data/tests/future.fy +24 -7
- data/tests/hash.fy +55 -38
- data/tests/method.fy +50 -43
- data/tests/nil_class.fy +37 -37
- data/tests/object.fy +152 -70
- data/tests/pattern_matching.fy +67 -31
- data/tests/range.fy +6 -6
- data/tests/set.fy +101 -4
- data/tests/stack.fy +14 -5
- data/tests/string.fy +115 -61
- data/tests/stringio.fy +18 -0
- data/tests/struct.fy +27 -0
- data/tests/symbol.fy +19 -6
- data/tests/true_class.fy +34 -34
- data/tests/tuple.fy +30 -12
- metadata +103 -81
- data/boot/rbx-compiler/compiler/ast/require.rb +0 -20
- data/examples/actor.fy +0 -37
- data/examples/curl_async.fy +0 -37
- data/lib/compiler/ast/require.fy +0 -15
- data/tests/number.fy +0 -135
- data/tests/parsing/sexp.fy +0 -50
data/lib/rbx/range.fy
CHANGED
|
@@ -2,26 +2,40 @@ class Range {
|
|
|
2
2
|
ruby_alias: 'to_a
|
|
3
3
|
ruby_alias: '==
|
|
4
4
|
ruby_alias: '===
|
|
5
|
+
ruby_alias: 'first
|
|
6
|
+
ruby_alias: 'last
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
def initialize: @start to: @end {
|
|
9
|
+
"""
|
|
10
|
+
@start Start element of Range.
|
|
11
|
+
@end End element of Range.
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
Initializes a new Range starting at @start and ending at @end.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
initialize(@start, @end)
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
def each: block {
|
|
20
|
+
"""
|
|
21
|
+
@block @Block@ to be called with every value in @self.
|
|
22
|
+
@return @self.
|
|
23
|
+
|
|
24
|
+
Calls @block on each value in @self. Used for iterating over a @Range@.
|
|
25
|
+
"""
|
|
26
|
+
|
|
13
27
|
try {
|
|
14
28
|
val = nil
|
|
15
29
|
each() |x| {
|
|
16
30
|
try {
|
|
17
31
|
val = block call: [x]
|
|
18
32
|
} catch (Fancy NextIteration) => ex {
|
|
19
|
-
val = ex
|
|
33
|
+
val = ex result
|
|
20
34
|
}
|
|
21
35
|
}
|
|
22
|
-
|
|
36
|
+
return self
|
|
23
37
|
} catch (Fancy BreakIteration) => ex {
|
|
24
|
-
ex
|
|
38
|
+
ex result
|
|
25
39
|
}
|
|
26
40
|
}
|
|
27
41
|
}
|
data/lib/rbx/regexp.fy
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
class Regexp {
|
|
2
|
+
"""
|
|
3
|
+
Regular Expression class. Used by Regexp literals in Fancy.
|
|
4
|
+
"""
|
|
5
|
+
|
|
2
6
|
ruby_alias: 'inspect
|
|
3
7
|
ruby_alias: 'to_s
|
|
4
8
|
|
|
@@ -9,8 +13,12 @@ class Regexp {
|
|
|
9
13
|
def i {
|
|
10
14
|
Regexp new(source(), true)
|
|
11
15
|
}
|
|
12
|
-
}
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
def Regexp new: string {
|
|
18
|
+
new(string)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
def Regexp [string] {
|
|
22
|
+
new(string)
|
|
23
|
+
}
|
|
16
24
|
}
|
data/lib/rbx/string.fy
CHANGED
|
@@ -10,8 +10,15 @@ class String {
|
|
|
10
10
|
ruby_alias: 'chomp
|
|
11
11
|
ruby_alias: 'inspect
|
|
12
12
|
ruby_alias: 'to_sym
|
|
13
|
+
ruby_alias: '<
|
|
14
|
+
ruby_alias: '>
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
alias_method: '[]: for_ruby: '[]=
|
|
17
|
+
alias_method: 'scan: for_ruby: 'scan
|
|
18
|
+
|
|
19
|
+
forwards_unary_ruby_methods
|
|
20
|
+
|
|
21
|
+
def [index] {
|
|
15
22
|
"""Given an Array of 2 Numbers, it returns the substring between the given indices.
|
|
16
23
|
If given a Number, returns the character at that index."""
|
|
17
24
|
|
|
@@ -103,4 +110,47 @@ class String {
|
|
|
103
110
|
def unpack: format {
|
|
104
111
|
unpack(format)
|
|
105
112
|
}
|
|
113
|
+
|
|
114
|
+
def replace: pattern with: replacement {
|
|
115
|
+
if: (replacement is_a?: Block) then: {
|
|
116
|
+
gsub(pattern, &replacement)
|
|
117
|
+
} else: {
|
|
118
|
+
gsub(pattern, replacement)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
def replace!: pattern with: replacement {
|
|
123
|
+
if: (replacement is_a?: Block) then: {
|
|
124
|
+
gsub!(pattern, &replacement)
|
|
125
|
+
} else: {
|
|
126
|
+
gsub!(pattern, replacement)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
def append: string {
|
|
131
|
+
"""
|
|
132
|
+
@string Other @String@ to append on @self.
|
|
133
|
+
@return @self, but modified.
|
|
134
|
+
|
|
135
|
+
Appends another @String@ onto this @String@.
|
|
136
|
+
|
|
137
|
+
Example usage:
|
|
138
|
+
str = \"hello\"
|
|
139
|
+
str append: \" world!\"
|
|
140
|
+
str # => \"hello world!\"
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
append(string)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
def includes?: substring {
|
|
147
|
+
"""
|
|
148
|
+
@substring @String@ to be checked if it's in @self.
|
|
149
|
+
@return @true if @substring is in @self, @false otherwise.
|
|
150
|
+
|
|
151
|
+
Indicates if a given substring is in @self.
|
|
152
|
+
"""
|
|
153
|
+
|
|
154
|
+
include?(substring)
|
|
155
|
+
}
|
|
106
156
|
}
|
data/lib/rbx/stringio.fy
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require("stringio")
|
|
2
|
+
|
|
3
|
+
class StringIO {
|
|
4
|
+
include: IOMixin
|
|
5
|
+
forwards_unary_ruby_methods
|
|
6
|
+
StringIO forwards_unary_ruby_methods
|
|
7
|
+
|
|
8
|
+
ruby_alias: '<<
|
|
9
|
+
|
|
10
|
+
def each: block {
|
|
11
|
+
each(&block)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
def each_line: block {
|
|
15
|
+
each_line(&block)
|
|
16
|
+
}
|
|
17
|
+
}
|
data/lib/rbx/symbol.fy
CHANGED
|
@@ -7,6 +7,20 @@ class Symbol {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
def inspect {
|
|
10
|
-
"'" ++
|
|
10
|
+
"'" ++ to_s
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
def defined? {
|
|
14
|
+
"""
|
|
15
|
+
@return @true, if @self is defined as a constant in senders scope, @false otherwise.
|
|
16
|
+
|
|
17
|
+
Indicates if a Symbol is defined as a constant in the senders scope.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
binding = Binding setup(Rubinius VariableScope of_sender(),
|
|
21
|
+
Rubinius CompiledMethod of_sender(),
|
|
22
|
+
Rubinius StaticScope of_sender())
|
|
23
|
+
|
|
24
|
+
binding send('self) class const_defined?(self)
|
|
11
25
|
}
|
|
12
26
|
}
|
data/lib/rbx/system.fy
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
require("open3")
|
|
2
2
|
|
|
3
3
|
class System {
|
|
4
|
+
"""
|
|
5
|
+
System class. Holds system-wide relevant methods.
|
|
6
|
+
"""
|
|
7
|
+
|
|
4
8
|
def System exit {
|
|
5
|
-
"
|
|
9
|
+
"""
|
|
10
|
+
Exit the running Fancy process.
|
|
11
|
+
"""
|
|
6
12
|
|
|
7
13
|
Kernel exit()
|
|
8
14
|
}
|
|
9
15
|
|
|
16
|
+
def System exit: exitcode {
|
|
17
|
+
"""
|
|
18
|
+
@exitcode Exit code (Fixnum) to be returned to the parent process.
|
|
19
|
+
|
|
20
|
+
Exit the running Fancy process with a given exit code.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
Kernel exit(exitcode)
|
|
24
|
+
}
|
|
25
|
+
|
|
10
26
|
def System do: command_str {
|
|
11
|
-
"
|
|
27
|
+
"""
|
|
28
|
+
Runs the given string as a system() command.
|
|
29
|
+
"""
|
|
12
30
|
|
|
13
31
|
Kernel system(command_str)
|
|
14
32
|
}
|
data/lib/rbx/tcp_server.fy
CHANGED
data/lib/rbx/tcp_socket.fy
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
require("socket")
|
|
2
2
|
|
|
3
3
|
class TCPSocket {
|
|
4
|
+
"""
|
|
5
|
+
TCP Socket class.
|
|
6
|
+
"""
|
|
7
|
+
|
|
4
8
|
def TCPSocket open: server port: port {
|
|
9
|
+
"""
|
|
10
|
+
@server Server hostname to open Socket on.
|
|
11
|
+
@port Server port to open Socket on.
|
|
12
|
+
|
|
13
|
+
Creates and opens a new @TCPSocket@ on @server and @port.
|
|
14
|
+
"""
|
|
15
|
+
|
|
5
16
|
open(server, port)
|
|
6
17
|
}
|
|
7
18
|
}
|
data/lib/rbx/time.fy
CHANGED
data/lib/rbx/tuple.fy
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
Tuple = Rubinius Tuple
|
|
2
2
|
class Tuple {
|
|
3
|
-
|
|
4
|
-
ruby_alias: 'to_a
|
|
3
|
+
forwards_unary_ruby_methods
|
|
5
4
|
|
|
6
|
-
def
|
|
5
|
+
def Tuple new: size {
|
|
7
6
|
"""
|
|
8
7
|
@size Size of the @Tuple@ (amount of values to hold).
|
|
9
8
|
|
|
@@ -11,7 +10,15 @@ class Tuple {
|
|
|
11
10
|
E.g. if @size is @2, creates a 2-Tuple.
|
|
12
11
|
"""
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
if: (size < 2) then: {
|
|
14
|
+
ArgumentError new: "Tuple size has to be a minimum of 2!" . raise!
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
new(size)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
def Tuple new {
|
|
21
|
+
ArgumentError new: "Cannot initialize empty Tuple!" . raise!
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
def at: idx {
|
|
@@ -26,7 +33,7 @@ class Tuple {
|
|
|
26
33
|
at(idx)
|
|
27
34
|
}
|
|
28
35
|
|
|
29
|
-
def
|
|
36
|
+
def [idx]: val {
|
|
30
37
|
"""
|
|
31
38
|
@idx Index of element to set.
|
|
32
39
|
@val Value to set at given index.
|
|
@@ -35,4 +42,6 @@ class Tuple {
|
|
|
35
42
|
"""
|
|
36
43
|
put(idx, val)
|
|
37
44
|
}
|
|
45
|
+
|
|
46
|
+
alias_method: 'at:put: for: '[]:
|
|
38
47
|
}
|
data/lib/set.fy
CHANGED
|
@@ -1,61 +1,176 @@
|
|
|
1
1
|
class Set {
|
|
2
|
-
"
|
|
2
|
+
"""
|
|
3
|
+
A simple Set data structure class.
|
|
4
|
+
"""
|
|
3
5
|
|
|
4
6
|
include: FancyEnumerable
|
|
5
|
-
read_slots: ['values]
|
|
6
7
|
|
|
7
|
-
def initialize:
|
|
8
|
-
"
|
|
9
|
-
@values
|
|
8
|
+
def initialize: values {
|
|
9
|
+
"""
|
|
10
|
+
@values @FancyEnumerable@ of values to be used as values for @self.
|
|
11
|
+
|
|
12
|
+
Initialize a new Set with a given collection of values.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
@hash = <[]>
|
|
16
|
+
values each: |v| {
|
|
17
|
+
@hash[v]: true
|
|
18
|
+
}
|
|
10
19
|
}
|
|
11
20
|
|
|
12
21
|
def initialize {
|
|
13
|
-
"
|
|
14
|
-
|
|
22
|
+
"""
|
|
23
|
+
Initialize a new empty Set.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
@hash = <[]>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
def values {
|
|
30
|
+
"""
|
|
31
|
+
@return Values in self as an @Array@.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
@hash keys
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
def size {
|
|
38
|
+
"""
|
|
39
|
+
@return Amount of values in @self as a @Fixnum@.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
@hash size
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
def empty? {
|
|
46
|
+
"""
|
|
47
|
+
@return @true, if Set is emty, @false otherwise.
|
|
48
|
+
|
|
49
|
+
Indicates, if a Set is empty.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
@hash empty?
|
|
15
53
|
}
|
|
16
54
|
|
|
17
55
|
def == other {
|
|
18
|
-
"
|
|
56
|
+
"""
|
|
57
|
+
@other @Set@ to compare @self against.
|
|
58
|
+
@return @true, if self is equal to @other, @false otherwise.
|
|
59
|
+
|
|
60
|
+
Indicates, if two Sets are equal.
|
|
61
|
+
"""
|
|
62
|
+
|
|
19
63
|
if: (other is_a?: Set) then: {
|
|
20
|
-
|
|
64
|
+
if: (size == (other size)) then: {
|
|
65
|
+
return other all?: |x| { includes?: x }
|
|
66
|
+
}
|
|
21
67
|
}
|
|
68
|
+
return false
|
|
22
69
|
}
|
|
23
70
|
|
|
24
|
-
def Set []
|
|
25
|
-
"
|
|
26
|
-
|
|
71
|
+
def Set [values] {
|
|
72
|
+
"""
|
|
73
|
+
@values @FancyEnumerable@ of values used for new Set.
|
|
74
|
+
|
|
75
|
+
Initialize a new Set with a given collection of values.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
Set new: values
|
|
27
79
|
}
|
|
28
80
|
|
|
29
81
|
def << value {
|
|
30
|
-
"
|
|
31
|
-
|
|
82
|
+
"""
|
|
83
|
+
@value Value to be inserted into @self.
|
|
84
|
+
@return @self.
|
|
85
|
+
|
|
86
|
+
Insert a value into the Set.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
@hash[value]: true
|
|
90
|
+
self
|
|
32
91
|
}
|
|
33
92
|
|
|
34
93
|
def includes?: value {
|
|
35
|
-
"
|
|
36
|
-
@
|
|
94
|
+
"""
|
|
95
|
+
@value Value to be checked for if included in @self.
|
|
96
|
+
@return @true if @value in @self, @false otherwise.
|
|
97
|
+
|
|
98
|
+
Indicates, if the Set includes a given value.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
@hash includes?: value
|
|
37
102
|
}
|
|
38
103
|
|
|
39
104
|
def each: block {
|
|
40
|
-
"
|
|
41
|
-
@
|
|
42
|
-
|
|
105
|
+
"""
|
|
106
|
+
@block @Block@ to be called with each value in @self.
|
|
107
|
+
@return @self.
|
|
43
108
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
109
|
+
Calls a given Block for each element of the Set.
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
@hash each_key: block
|
|
113
|
+
self
|
|
50
114
|
}
|
|
51
115
|
|
|
52
116
|
def to_s {
|
|
53
|
-
"
|
|
54
|
-
|
|
117
|
+
"""
|
|
118
|
+
Returns a @String@ representation of a Set.
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
"Set[" ++ (values join: ", ") ++ "]"
|
|
55
122
|
}
|
|
56
123
|
|
|
57
124
|
def inspect {
|
|
58
|
-
"
|
|
59
|
-
|
|
125
|
+
"""
|
|
126
|
+
Returns a detailed @String@ representation of a Set.
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
"Set[" ++ (values map: 'inspect . join: ", " . to_s) ++ "]"
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
def remove: obj {
|
|
133
|
+
"""
|
|
134
|
+
@obj Object to be removed from @self.
|
|
135
|
+
|
|
136
|
+
Removes a given object from a Set, if available.
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
@hash delete: obj
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
def + other {
|
|
143
|
+
"""
|
|
144
|
+
@other Other Set to use for creating union Set.
|
|
145
|
+
@return Union Set containing all values in both @self and @other.
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
Set[values + (other values)]
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
def - other {
|
|
152
|
+
"""
|
|
153
|
+
@other Other Set to use for creating difference Set.
|
|
154
|
+
@return Difference Set by removing all values from @self that are in @other.
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
s = Set[values]
|
|
158
|
+
other values each: |v| {
|
|
159
|
+
s remove: v
|
|
160
|
+
}
|
|
161
|
+
s
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
def & other {
|
|
165
|
+
"""
|
|
166
|
+
@other Other Set to use for creating Set.
|
|
167
|
+
@return Intersection Set containing only values that are in both @self and @other.
|
|
168
|
+
"""
|
|
169
|
+
|
|
170
|
+
s = Set[values]
|
|
171
|
+
s values each: |v| {
|
|
172
|
+
{ s remove: v } unless: (other includes?: v)
|
|
173
|
+
}
|
|
174
|
+
s
|
|
60
175
|
}
|
|
61
176
|
}
|