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/date.fy
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
require("date")
|
|
2
2
|
|
|
3
3
|
class Date {
|
|
4
|
+
"""
|
|
5
|
+
Date class. Used for timely stuff.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
forwards_unary_ruby_methods
|
|
9
|
+
metaclass forwards_unary_ruby_methods
|
|
10
|
+
|
|
4
11
|
metaclass ruby_alias: 'today
|
|
5
12
|
ruby_alias: '==
|
|
6
13
|
ruby_alias: '-
|
|
7
14
|
ruby_alias: '+
|
|
15
|
+
ruby_alias: '<
|
|
16
|
+
ruby_alias: '>
|
|
8
17
|
|
|
9
18
|
def != other {
|
|
10
19
|
self == other not
|
data/lib/rbx/directory.fy
CHANGED
|
@@ -43,4 +43,22 @@ class Directory {
|
|
|
43
43
|
IOError new: (e message) . raise!
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
|
|
47
|
+
def self list: pattern {
|
|
48
|
+
"""
|
|
49
|
+
@pattern Directory pattern or name containing files to be returned as an @Array@.
|
|
50
|
+
@return @Array@ of files matching directory @pattern.
|
|
51
|
+
|
|
52
|
+
Example usage:
|
|
53
|
+
Directory list: \"tests/**/*.fy\" # => [\"tests/file1.fy\", \"tests/more/file2.fy\"]
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
match pattern {
|
|
57
|
+
case /\/$/ -> pattern = pattern + "*"
|
|
58
|
+
case "." -> pattern = pattern + "/*"
|
|
59
|
+
case ".." -> pattern = pattern + "/*"
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
Dir glob(pattern)
|
|
63
|
+
}
|
|
46
64
|
}
|
data/lib/rbx/exception.fy
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
class Exception {
|
|
2
|
+
forwards_unary_ruby_methods
|
|
3
|
+
}
|
|
4
|
+
|
|
1
5
|
class StandardError {
|
|
2
|
-
|
|
3
|
-
|
|
6
|
+
"""
|
|
7
|
+
StandardError. Base class of most Exception classes.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
forwards_unary_ruby_methods
|
|
4
11
|
|
|
5
12
|
def initialize {
|
|
6
13
|
"Creates a new Exception with an empty message."
|
data/lib/rbx/fiber.fy
CHANGED
|
@@ -1,22 +1,40 @@
|
|
|
1
|
-
require("fiber")
|
|
2
|
-
|
|
3
1
|
Fiber = Rubinius Fiber
|
|
4
2
|
|
|
5
3
|
class Fiber {
|
|
4
|
+
forwards_unary_ruby_methods
|
|
5
|
+
metaclass forwards_unary_ruby_methods
|
|
6
|
+
|
|
6
7
|
metaclass ruby_alias: 'yield
|
|
7
|
-
metaclass ruby_alias: 'current
|
|
8
8
|
ruby_alias: 'resume
|
|
9
|
-
ruby_alias: 'alive?
|
|
10
9
|
|
|
11
10
|
def self new: block {
|
|
11
|
+
"""
|
|
12
|
+
@block @Block@ to be run in a new Fiber.
|
|
13
|
+
|
|
14
|
+
Creates a new Fiber running @block.
|
|
15
|
+
"""
|
|
16
|
+
|
|
12
17
|
new(&block)
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
def Fiber yield: vals {
|
|
21
|
+
"""
|
|
22
|
+
@vals @Array@ of values to pass along to parent @Fiber@.
|
|
23
|
+
|
|
24
|
+
Returns execution control to the parent @Fiber@ and passes along @vals.
|
|
25
|
+
"""
|
|
26
|
+
|
|
16
27
|
yield(*vals)
|
|
17
28
|
}
|
|
18
29
|
|
|
19
30
|
def resume: vals {
|
|
31
|
+
"""
|
|
32
|
+
@vals @Array@ of values to pass along to @self for resuming.
|
|
33
|
+
|
|
34
|
+
Resumes @self (if paused) or raises an exception, if @Fiber@ is dead.
|
|
35
|
+
Passes along @vals as the return value of the last call to @yield in @self.
|
|
36
|
+
"""
|
|
37
|
+
|
|
20
38
|
resume(*vals)
|
|
21
39
|
}
|
|
22
40
|
}
|
data/lib/rbx/file.fy
CHANGED
|
@@ -22,11 +22,11 @@ class File {
|
|
|
22
22
|
|
|
23
23
|
E.g. to open a File with read access and read all lines and print them to STDOUT:
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
File open: \"foo.txt\" modes: ['read] with: |f| {
|
|
26
|
+
{ f eof? } while_false: {
|
|
27
|
+
f readln println
|
|
28
|
+
}
|
|
28
29
|
}
|
|
29
|
-
}
|
|
30
30
|
"""
|
|
31
31
|
|
|
32
32
|
modes_str = modes_str: modes_arr
|
|
@@ -93,7 +93,7 @@ class File {
|
|
|
93
93
|
|
|
94
94
|
str = ""
|
|
95
95
|
modes_arr each: |m| {
|
|
96
|
-
str
|
|
96
|
+
str << (@@open_mode_conversions[m])
|
|
97
97
|
}
|
|
98
98
|
str uniq join: ""
|
|
99
99
|
}
|
data/lib/rbx/fixnum.fy
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
require: "../number"
|
|
2
2
|
|
|
3
3
|
class Fixnum {
|
|
4
|
+
"""
|
|
5
|
+
Standard class for integer values in Fancy.
|
|
6
|
+
"""
|
|
7
|
+
|
|
4
8
|
include: Number
|
|
5
9
|
|
|
6
10
|
ruby_alias: '==
|
|
@@ -18,6 +22,7 @@ class Fixnum {
|
|
|
18
22
|
ruby_alias: 'to_f
|
|
19
23
|
ruby_alias: '**
|
|
20
24
|
ruby_alias: '&
|
|
25
|
+
ruby_alias: '|
|
|
21
26
|
|
|
22
27
|
alias_method: 'to_s: for: 'to_s
|
|
23
28
|
alias_method: 'modulo: for: 'modulo
|
data/lib/rbx/float.fy
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
class Float {
|
|
2
|
+
"""
|
|
3
|
+
Standard class for floating point number values in Fancy.
|
|
4
|
+
"""
|
|
5
|
+
|
|
2
6
|
include: Number
|
|
3
7
|
|
|
8
|
+
forwards_unary_ruby_methods
|
|
9
|
+
|
|
4
10
|
ruby_alias: '+
|
|
5
11
|
ruby_alias: '-
|
|
6
12
|
ruby_alias: '*
|
|
@@ -8,8 +14,10 @@ class Float {
|
|
|
8
14
|
ruby_alias: '==
|
|
9
15
|
ruby_alias: '>=
|
|
10
16
|
ruby_alias: '<=
|
|
11
|
-
ruby_alias: '<=>
|
|
12
|
-
ruby_alias: 'to_i
|
|
13
|
-
ruby_alias: 'to_f
|
|
14
17
|
ruby_alias: '**
|
|
18
|
+
ruby_alias: '<
|
|
19
|
+
ruby_alias: '>
|
|
20
|
+
|
|
21
|
+
alias_method: 'modulo: for: 'modulo
|
|
22
|
+
alias_method: ":%" for: "modulo:" # use a : so we dont overwrite ruby's % operator
|
|
15
23
|
}
|
data/lib/rbx/hash.fy
CHANGED
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
class Hash {
|
|
2
|
+
forwards_unary_ruby_methods
|
|
2
3
|
|
|
3
|
-
alias_method: ":size" for: 'size
|
|
4
4
|
alias_method: ":[]" for: '[]
|
|
5
5
|
alias_method: 'at:put: for: "[]="
|
|
6
|
+
alias_method: '[]: for: "[]="
|
|
6
7
|
alias_method: 'at: for: '[]
|
|
7
|
-
ruby_alias: 'keys
|
|
8
|
-
ruby_alias: 'values
|
|
9
8
|
ruby_alias: '==
|
|
10
9
|
|
|
11
|
-
def inspect {
|
|
12
|
-
str = "<["
|
|
13
|
-
max = size - 1
|
|
14
|
-
i = 0
|
|
15
|
-
each: |key,val| {
|
|
16
|
-
str = str ++ (key inspect) ++ " => " ++ (val inspect)
|
|
17
|
-
{ str = str + ", " } if: (i < max)
|
|
18
|
-
i = i + 1
|
|
19
|
-
}
|
|
20
|
-
str = str + "]>"
|
|
21
|
-
str
|
|
22
|
-
}
|
|
23
|
-
|
|
24
10
|
def each: block {
|
|
25
11
|
each(&block)
|
|
26
12
|
}
|
|
@@ -36,4 +22,33 @@ class Hash {
|
|
|
36
22
|
def map: block {
|
|
37
23
|
map(&block)
|
|
38
24
|
}
|
|
25
|
+
|
|
26
|
+
def delete: key {
|
|
27
|
+
"""
|
|
28
|
+
@key Key of key-value pair to be deleted in @self.
|
|
29
|
+
|
|
30
|
+
Deletes a key-value pair from @self.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
delete(key)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
def merge: other_hash {
|
|
37
|
+
merge(other_hash)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
def merge!: other_hash {
|
|
41
|
+
merge!(other_hash)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
def includes?: key {
|
|
45
|
+
"""
|
|
46
|
+
@key Key to search for.
|
|
47
|
+
@return @true, if Hash includes @key, @false otherwise.
|
|
48
|
+
|
|
49
|
+
Indicates if a given key is in @self.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
include?(key)
|
|
53
|
+
}
|
|
39
54
|
}
|
data/lib/rbx/integer.fy
CHANGED
data/lib/rbx/io.fy
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
class
|
|
2
|
-
ruby_alias: 'readlines
|
|
3
|
-
ruby_alias: 'readline
|
|
4
|
-
ruby_alias: 'read
|
|
5
|
-
ruby_alias: 'close
|
|
6
|
-
ruby_alias: 'eof?
|
|
7
|
-
|
|
1
|
+
class IOMixin {
|
|
8
2
|
def readln {
|
|
9
3
|
readline
|
|
10
4
|
}
|
|
@@ -28,3 +22,19 @@ class IO {
|
|
|
28
22
|
alias_method: 'write: for: 'print:
|
|
29
23
|
alias_method: 'writeln: for: 'println:
|
|
30
24
|
}
|
|
25
|
+
|
|
26
|
+
class IO {
|
|
27
|
+
"""
|
|
28
|
+
Base class for IO related classes (like @File@, @Socket@, @Console@ etc.).
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
include: IOMixin
|
|
32
|
+
|
|
33
|
+
ruby_alias: 'readlines
|
|
34
|
+
ruby_alias: 'readline
|
|
35
|
+
ruby_alias: 'read
|
|
36
|
+
ruby_alias: 'close
|
|
37
|
+
ruby_alias: 'eof?
|
|
38
|
+
|
|
39
|
+
forwards_unary_ruby_methods
|
|
40
|
+
}
|
data/lib/rbx/match_data.fy
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
class MatchData {
|
|
2
|
+
"""
|
|
3
|
+
MatchData instances are created when using the #=== match operator
|
|
4
|
+
(e.g. by using match/case expressions).
|
|
5
|
+
"""
|
|
6
|
+
|
|
2
7
|
ruby_alias: 'size
|
|
8
|
+
ruby_alias: '[]
|
|
3
9
|
|
|
4
10
|
def at: idx {
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
"""
|
|
12
|
+
@idx Index of value to get.
|
|
13
|
+
@return Value at index @idx.
|
|
14
|
+
"""
|
|
7
15
|
|
|
8
|
-
|
|
9
|
-
at: idx
|
|
16
|
+
self[idx]
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
def to_a {
|
|
20
|
+
"""
|
|
21
|
+
@return @Array@ representation of @self containing matched values of @self.
|
|
22
|
+
"""
|
|
23
|
+
|
|
13
24
|
arr = []
|
|
14
25
|
self size times: |i| {
|
|
15
26
|
arr << (at: i)
|
data/lib/rbx/method.fy
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
class MethodMixin {
|
|
2
|
+
"""
|
|
3
|
+
Mixin class with common methods included by @Method@ and @UnboundMethod@.
|
|
4
|
+
"""
|
|
5
|
+
|
|
2
6
|
def documentation {
|
|
7
|
+
"""
|
|
8
|
+
@return Docstring for @self.
|
|
9
|
+
"""
|
|
10
|
+
|
|
3
11
|
Fancy Documentation for: (executable())
|
|
4
12
|
}
|
|
5
13
|
|
|
6
|
-
def documentation:
|
|
7
|
-
|
|
14
|
+
def documentation: docstring {
|
|
15
|
+
"""
|
|
16
|
+
@docstring New docstring for @self.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
Fancy Documentation for: (executable()) is: docstring
|
|
8
20
|
}
|
|
9
21
|
|
|
10
22
|
def visibility {
|
|
11
23
|
"""
|
|
12
|
-
|
|
24
|
+
@return The visibility (@'private, @'protected, @'public) of a @Method@ in its defined context, if any.
|
|
13
25
|
"""
|
|
14
26
|
entry = @defined_in method_table() lookup(@name)
|
|
15
27
|
{ entry visibility() } if: entry
|
|
@@ -17,33 +29,54 @@ class MethodMixin {
|
|
|
17
29
|
|
|
18
30
|
def public? {
|
|
19
31
|
"""
|
|
20
|
-
|
|
32
|
+
@return @true, if the @Method@ is public in its defined context.
|
|
21
33
|
"""
|
|
22
34
|
visibility == 'public
|
|
23
35
|
}
|
|
24
36
|
|
|
25
37
|
def protected? {
|
|
26
38
|
"""
|
|
27
|
-
|
|
39
|
+
@return @true, if the @Method@ is protected in its defined context.
|
|
28
40
|
"""
|
|
29
41
|
visibility == 'protected
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
def private? {
|
|
33
45
|
"""
|
|
34
|
-
|
|
46
|
+
@return @true, if the @Method@ is private in its defined context.
|
|
35
47
|
"""
|
|
36
48
|
visibility == 'private
|
|
37
49
|
}
|
|
50
|
+
|
|
51
|
+
def tests {
|
|
52
|
+
"""
|
|
53
|
+
Returns an Array of all the FancySpec SpecTests defined for a
|
|
54
|
+
Method.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
@__method_tests__ = @__method_tests__ || []
|
|
58
|
+
@__method_tests__
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
def test: test_block {
|
|
62
|
+
it = FancySpec new: self
|
|
63
|
+
test_block call: [it]
|
|
64
|
+
tests << it
|
|
65
|
+
}
|
|
38
66
|
}
|
|
39
67
|
|
|
40
68
|
class Method {
|
|
41
69
|
ruby_alias: 'arity
|
|
42
70
|
include: MethodMixin
|
|
71
|
+
forwards_unary_ruby_methods
|
|
43
72
|
}
|
|
44
73
|
|
|
45
74
|
class UnboundMethod {
|
|
75
|
+
"""
|
|
76
|
+
An instance UnboundMethod represents a Method object not bound to a specific @Class@ or @Object@.
|
|
77
|
+
"""
|
|
78
|
+
|
|
46
79
|
ruby_alias: 'arity
|
|
47
80
|
include: MethodMixin
|
|
81
|
+
forwards_unary_ruby_methods
|
|
48
82
|
}
|
|
49
|
-
|
data/lib/rbx/name_error.fy
CHANGED
data/lib/rbx/object.fy
CHANGED
|
@@ -1,81 +1,149 @@
|
|
|
1
|
-
class Class {
|
|
2
|
-
def alias_method: new for: old {
|
|
3
|
-
alias_method(new, old)
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
def ruby_alias: method_name {
|
|
7
|
-
alias_method(":" + (method_name to_s), method_name)
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
class String {
|
|
12
|
-
alias_method: ":+" for: "+"
|
|
13
|
-
}
|
|
14
|
-
|
|
15
1
|
class Object {
|
|
16
|
-
|
|
17
2
|
ruby_alias: '==
|
|
18
3
|
ruby_alias: '===
|
|
19
4
|
ruby_alias: 'class
|
|
20
5
|
ruby_alias: 'inspect
|
|
6
|
+
ruby_alias: 'object_id
|
|
7
|
+
ruby_alias: 'instance_variables
|
|
21
8
|
|
|
22
9
|
def initialize {
|
|
23
10
|
initialize()
|
|
24
11
|
}
|
|
25
12
|
|
|
13
|
+
def require: file_path {
|
|
14
|
+
"""
|
|
15
|
+
Loads and evaluates a given Fancy source file by trying to find the specified
|
|
16
|
+
@file_path in Fancy's loadpath (see @Fancy::CodeLoader@).
|
|
17
|
+
Relative paths are allowed (and by default expected).
|
|
18
|
+
"""
|
|
19
|
+
Fancy CodeLoader require: file_path
|
|
20
|
+
}
|
|
21
|
+
|
|
26
22
|
def dclone {
|
|
27
23
|
"Returns a deep clone of self using Ruby's Marshal class."
|
|
28
24
|
Marshal load(Marshal dump(self))
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
def to_s {
|
|
28
|
+
"""
|
|
29
|
+
@return @String@ represenation of @self.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
32
|
to_s()
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
def set_slot: slotname value: val {
|
|
36
|
+
"""
|
|
37
|
+
@slotname Name of slot to be set.
|
|
38
|
+
@val Value for slot to be set.
|
|
39
|
+
|
|
40
|
+
Sets an object's slot with a given value.
|
|
41
|
+
"""
|
|
42
|
+
|
|
36
43
|
instance_variable_set("@" ++ slotname, val)
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
def get_slot: slotname {
|
|
47
|
+
"""
|
|
48
|
+
@slotname Name of slot to get the value of.
|
|
49
|
+
@return Value of slot with name @slotname.
|
|
50
|
+
|
|
51
|
+
Returns the value of a slot of @self.
|
|
52
|
+
"""
|
|
53
|
+
|
|
40
54
|
instance_variable_get("@" ++ slotname)
|
|
41
55
|
}
|
|
42
56
|
|
|
43
57
|
def define_singleton_method: name with: block {
|
|
58
|
+
"""
|
|
59
|
+
@name Name of the method to be defined on @self.
|
|
60
|
+
@block @Block@ to be used as the method's body.
|
|
61
|
+
|
|
62
|
+
Dynamically defines a method on @self's metaclass (a singleton method) using a given @Block@.
|
|
63
|
+
"""
|
|
64
|
+
|
|
44
65
|
metaclass define_method: name with: block
|
|
45
66
|
}
|
|
46
67
|
|
|
47
68
|
def undefine_singleton_method: name {
|
|
69
|
+
"""
|
|
70
|
+
@name Name of the method to be undefined no @self's metaclass.
|
|
71
|
+
|
|
72
|
+
Undefines a singleton method of @self.
|
|
73
|
+
"""
|
|
74
|
+
|
|
48
75
|
metaclass undefine_method: name
|
|
49
76
|
}
|
|
50
77
|
|
|
51
78
|
def is_a?: class {
|
|
52
|
-
"
|
|
79
|
+
"""
|
|
80
|
+
@class @Class@ to check for if @self is an instance of.
|
|
81
|
+
@return @true if @self is an instance of @class, @false otherwise.
|
|
82
|
+
|
|
83
|
+
Indicates, if an object is an instance of a given Class.
|
|
84
|
+
"""
|
|
85
|
+
|
|
53
86
|
is_a?(class)
|
|
54
87
|
}
|
|
55
88
|
|
|
56
89
|
def kind_of?: class {
|
|
57
|
-
"
|
|
90
|
+
"""
|
|
91
|
+
Same as Object#is_a?:
|
|
92
|
+
Indicates, if an object is an instance of a given Class.
|
|
93
|
+
"""
|
|
94
|
+
|
|
58
95
|
kind_of?(class)
|
|
59
96
|
}
|
|
60
97
|
|
|
61
|
-
def
|
|
98
|
+
def receive_message: message {
|
|
99
|
+
"""
|
|
100
|
+
@message Name of message to be sent to @self dynamically.
|
|
101
|
+
|
|
102
|
+
Dynamically sends a given message (without parameters) to @self.
|
|
103
|
+
"""
|
|
104
|
+
|
|
62
105
|
send(message_name: message)
|
|
63
106
|
}
|
|
64
107
|
|
|
65
|
-
def
|
|
66
|
-
|
|
108
|
+
def receive_message: message with_params: params {
|
|
109
|
+
"""
|
|
110
|
+
@message Name of message to be sent to @self dynamically.
|
|
111
|
+
@params @Array@ of parameters used with @message.
|
|
112
|
+
|
|
113
|
+
Dynamically sends a given message with parameters to @self.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
ruby: (message_name: message) args: params
|
|
67
117
|
}
|
|
68
118
|
|
|
69
119
|
def message_name: symbol {
|
|
70
120
|
symbol = symbol to_s
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
121
|
+
match symbol =~ /:/ {
|
|
122
|
+
case nil ->
|
|
123
|
+
":" ++ symbol
|
|
124
|
+
case _ ->
|
|
125
|
+
symbol
|
|
75
126
|
}
|
|
76
127
|
}
|
|
77
128
|
|
|
78
129
|
def responds_to?: message {
|
|
130
|
+
"""
|
|
131
|
+
@message The message to check for (preferably a Symbol).
|
|
132
|
+
@return @true if @self responds to @message, @false otherwise.
|
|
133
|
+
|
|
134
|
+
Indicates if an object responds to a given message.
|
|
135
|
+
"""
|
|
136
|
+
|
|
79
137
|
respond_to?(message_name: message)
|
|
80
138
|
}
|
|
139
|
+
|
|
140
|
+
def extend: class {
|
|
141
|
+
"""
|
|
142
|
+
@class @Class@ to extend @self with.
|
|
143
|
+
|
|
144
|
+
Extends @self with the methods in @class (by including its methods in @self's metaclass).
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
metaclass include: class
|
|
148
|
+
}
|
|
81
149
|
}
|