fancy 0.9.0 → 0.10.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/bin/fancy +1 -1
- data/bin/fspec +1 -1
- data/bin/ifancy +1 -0
- data/boot/compiler/parser/ext/fancy_parser.bundle +0 -0
- data/boot/fancy_ext/array.rb +0 -1
- data/boot/fancy_ext/object.rb +10 -0
- data/boot/rbx-compiler/parser/Makefile +207 -0
- data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
- data/boot/rbx-compiler/parser/lexer.c +2314 -0
- data/boot/rbx-compiler/parser/lexer.h +316 -0
- data/boot/rbx-compiler/parser/parser.c +3133 -0
- data/boot/rbx-compiler/parser/parser.h +131 -0
- data/doc/api/fancy.jsonp +1 -1
- data/examples/echo.fy +1 -1
- data/examples/stupid_quicksort.fy +1 -1
- data/lib/array.fy +4 -0
- data/lib/block.fy +11 -8
- data/lib/class.fy +21 -0
- data/lib/compiler/ast.fy +1 -0
- data/lib/compiler/ast/identifier.fy +1 -3
- data/lib/compiler/ast/method_spec.fy +6 -0
- data/lib/contracts.fy +2 -2
- data/lib/documentation.fy +25 -24
- data/lib/enumerable.fy +38 -21
- data/lib/fancy_spec.fy +24 -17
- data/lib/fdoc.fy +32 -16
- data/lib/future.fy +26 -1
- data/lib/object.fy +4 -1
- data/lib/parser/ext/Makefile +207 -0
- data/lib/parser/ext/fancy_parser.bundle +0 -0
- data/lib/parser/ext/lexer.c +2442 -0
- data/lib/parser/ext/lexer.h +316 -0
- data/lib/parser/ext/lexer.lex +4 -4
- data/lib/parser/ext/parser.c +3400 -0
- data/lib/parser/ext/parser.h +135 -0
- data/lib/parser/ext/parser.y +52 -74
- data/lib/parser/methods.fy +20 -8
- data/lib/parser/parse_error.fy +2 -2
- data/lib/range.fy +1 -1
- data/lib/rbx.fy +1 -0
- data/lib/rbx/block.fy +0 -12
- data/lib/rbx/class.fy +1 -1
- data/lib/rbx/compiled_method.fy +4 -0
- data/lib/{eval.fy → rbx/eval.fy} +3 -3
- data/lib/rbx/hash.fy +13 -3
- data/lib/rbx/method.fy +1 -0
- data/lib/rbx/object.fy +5 -1
- data/lib/rbx/range.fy +1 -1
- data/lib/rbx/scopes.fy +15 -0
- data/lib/rbx/symbol.fy +4 -0
- data/lib/rbx/thread.fy +1 -1
- data/lib/set.fy +11 -0
- data/lib/string.fy +17 -17
- data/lib/symbol.fy +7 -3
- data/lib/tuple.fy +3 -8
- data/lib/version.fy +1 -1
- data/ruby_lib/fancy +1 -1
- data/ruby_lib/fancy.rb +6 -19
- data/ruby_lib/interactive/hilight.rb +5 -5
- data/tests/block.fy +36 -13
- data/tests/class.fy +124 -120
- data/tests/contracts.fy +9 -8
- data/tests/future.fy +29 -10
- data/tests/method.fy +5 -0
- data/tests/range.fy +8 -0
- data/tests/set.fy +16 -6
- data/tests/struct.fy +4 -4
- metadata +60 -55
- data/lib/queue.fy +0 -7
- data/tests/future_proxy.fy +0 -8
data/lib/rbx/hash.fy
CHANGED
@@ -72,9 +72,15 @@ class Hash {
|
|
72
72
|
"""
|
73
73
|
|
74
74
|
match default_value {
|
75
|
-
case Block ->
|
75
|
+
case Block ->
|
76
|
+
@got_default_proc = true
|
77
|
+
@default = nil
|
78
|
+
@default_proc = default_value
|
79
|
+
case _ ->
|
80
|
+
@got_default_proc = false
|
81
|
+
@default = default_value
|
82
|
+
@default_proc = nil
|
76
83
|
}
|
77
|
-
@default = default_value
|
78
84
|
}
|
79
85
|
|
80
86
|
def default {
|
@@ -82,7 +88,11 @@ class Hash {
|
|
82
88
|
@return Default value for @self.
|
83
89
|
"""
|
84
90
|
|
85
|
-
@
|
91
|
+
if: @got_default_proc then: {
|
92
|
+
@default_proc
|
93
|
+
} else: {
|
94
|
+
@default
|
95
|
+
}
|
86
96
|
}
|
87
97
|
|
88
98
|
def default_for: key {
|
data/lib/rbx/method.fy
CHANGED
data/lib/rbx/object.fy
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
class Object {
|
2
|
-
ruby_aliases: [ '==, '===, 'class, 'inspect, 'object_id, 'instance_variables, 'methods, 'instance_variable_get, 'instance_variable_set ]
|
2
|
+
ruby_aliases: [ '==, '===, 'class, 'inspect, 'object_id, 'instance_variables, 'methods, 'instance_variable_get, 'instance_variable_set, 'singleton_methods ]
|
3
3
|
|
4
4
|
def initialize {
|
5
5
|
initialize()
|
6
6
|
}
|
7
7
|
|
8
|
+
def to_a {
|
9
|
+
[self]
|
10
|
+
}
|
11
|
+
|
8
12
|
def require: file_path {
|
9
13
|
"""
|
10
14
|
Loads and evaluates a given Fancy source file by trying to find the specified
|
data/lib/rbx/range.fy
CHANGED
data/lib/rbx/scopes.fy
ADDED
data/lib/rbx/symbol.fy
CHANGED
data/lib/rbx/thread.fy
CHANGED
@@ -29,7 +29,7 @@ class Thread {
|
|
29
29
|
|
30
30
|
Thread metaclass ruby_alias: 'abort_on_exception
|
31
31
|
Thread metaclass ruby_alias: 'current
|
32
|
-
Thread metaclass ruby_alias: 'critical
|
32
|
+
# Thread metaclass ruby_alias: 'critical
|
33
33
|
Thread metaclass ruby_alias: 'exit
|
34
34
|
Thread metaclass ruby_alias: 'list
|
35
35
|
Thread metaclass ruby_alias: 'main
|
data/lib/set.fy
CHANGED
@@ -150,6 +150,17 @@ class Set {
|
|
150
150
|
@hash delete: obj
|
151
151
|
}
|
152
152
|
|
153
|
+
def clear {
|
154
|
+
"""
|
155
|
+
@return @self.
|
156
|
+
|
157
|
+
Removes all elements from @self.
|
158
|
+
"""
|
159
|
+
|
160
|
+
@hash = <[]>
|
161
|
+
self
|
162
|
+
}
|
163
|
+
|
153
164
|
def + other {
|
154
165
|
"""
|
155
166
|
@other Other Set to use for creating union Set.
|
data/lib/string.fy
CHANGED
@@ -10,23 +10,23 @@ class String {
|
|
10
10
|
|
11
11
|
include: Fancy Enumerable
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
13
|
+
method_documentation: <[
|
14
|
+
'== => """
|
15
|
+
Compares @self to another @String@ and returns @true, if equal, @false otherwise.
|
16
|
+
""",
|
17
|
+
'uppercase => """
|
18
|
+
@return Uppercased version of @self.
|
19
|
+
|
20
|
+
Example:
|
21
|
+
\"hello world\" uppercase # => \"HELLO WORLD\"
|
22
|
+
""",
|
23
|
+
'lowercase => """
|
24
|
+
@return Lowercased version of @self.
|
25
|
+
|
26
|
+
Example:
|
27
|
+
\"HELLO WORLD\" lowercase # => \"hello world\"
|
28
|
+
"""
|
29
|
+
]>
|
30
30
|
|
31
31
|
def ++ other {
|
32
32
|
"""
|
data/lib/symbol.fy
CHANGED
@@ -56,13 +56,17 @@ class Symbol {
|
|
56
56
|
def arity {
|
57
57
|
m = message_name to_s
|
58
58
|
match m {
|
59
|
-
case /^:[a-zA-Z0-9_]+$/ -> m count: |c| { c == ":" }
|
60
|
-
case /^:\W+$/ -> 2
|
61
|
-
case _ -> m count: |c| { c == ":" } + 1
|
59
|
+
case /^:[a-zA-Z0-9_]+$/ -> m count: |c| { c == ":" } # unary message
|
60
|
+
case /^:\W+$/ -> 2 # binary operator
|
61
|
+
case _ -> m count: |c| { c == ":" } + 1 # multi-arg message
|
62
62
|
}
|
63
63
|
}
|
64
64
|
|
65
65
|
def to_sym {
|
66
|
+
"""
|
67
|
+
@return @self.
|
68
|
+
"""
|
69
|
+
|
66
70
|
self
|
67
71
|
}
|
68
72
|
|
data/lib/tuple.fy
CHANGED
@@ -59,19 +59,14 @@ class Tuple {
|
|
59
59
|
Returns sub-array starting at from: and going to to:
|
60
60
|
"""
|
61
61
|
|
62
|
-
if:
|
63
|
-
|
64
|
-
}
|
65
|
-
if: (to < 0) then: {
|
66
|
-
to = size + to
|
67
|
-
}
|
62
|
+
{ from = size + from } if: $ from < 0
|
63
|
+
{ to = size + to } if: $ to < 0
|
68
64
|
subarr = []
|
69
65
|
try {
|
70
66
|
from upto: to do: |i| {
|
71
67
|
subarr << (at: i)
|
72
68
|
}
|
73
|
-
} catch ObjectBoundsExceededError {
|
74
|
-
}
|
69
|
+
} catch ObjectBoundsExceededError {}
|
75
70
|
subarr
|
76
71
|
}
|
77
72
|
|
data/lib/version.fy
CHANGED
data/ruby_lib/fancy
CHANGED
@@ -25,7 +25,7 @@ begin
|
|
25
25
|
Fancy::CodeLoader.push_loadpath File.expand_path("../lib", base)
|
26
26
|
|
27
27
|
# Load compiler+eval support
|
28
|
-
Fancy::CodeLoader.load_compiled_file File.expand_path("../lib/eval", base)
|
28
|
+
Fancy::CodeLoader.load_compiled_file File.expand_path("../lib/rbx/eval", base)
|
29
29
|
|
30
30
|
# Run main
|
31
31
|
Fancy::CodeLoader.load_compiled_file File.expand_path("../lib/main", base)
|
data/ruby_lib/fancy.rb
CHANGED
@@ -12,28 +12,15 @@ bcl.load_compiled_file File.expand_path("../lib/rbx/code_loader", base)
|
|
12
12
|
Fancy::CodeLoader.push_loadpath File.expand_path("../lib", base)
|
13
13
|
|
14
14
|
# Load compiler+eval support
|
15
|
-
Fancy::CodeLoader.load_compiled_file File.expand_path("../lib/eval", base)
|
15
|
+
Fancy::CodeLoader.load_compiled_file File.expand_path("../lib/rbx/eval", base)
|
16
16
|
|
17
17
|
class Object
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
if i % 2 == 0
|
23
|
-
method_name << a
|
24
|
-
else
|
25
|
-
args << a
|
26
|
-
end
|
27
|
-
end
|
28
|
-
return [method_name.join(":") + ":", args]
|
29
|
-
end
|
30
|
-
|
31
|
-
def fy(*array_or_name)
|
32
|
-
if array_or_name.size > 1
|
33
|
-
message_name, args = fancy_message_args array_or_name
|
34
|
-
self.send(message_name, *args)
|
18
|
+
def fy(message)
|
19
|
+
case message
|
20
|
+
when Hash
|
21
|
+
__send__(message.keys.join(":") << ":", *message.values)
|
35
22
|
else
|
36
|
-
|
23
|
+
__send__(":#{message}")
|
37
24
|
end
|
38
25
|
end
|
39
26
|
|
@@ -9,7 +9,8 @@ module CodeRay
|
|
9
9
|
file_extension 'fy'
|
10
10
|
|
11
11
|
SPECIAL_FORMS = %w[
|
12
|
-
|
12
|
+
self super return return_local def class
|
13
|
+
throw try catch finally retry match case
|
13
14
|
] # :nodoc:
|
14
15
|
|
15
16
|
CORE_FORMS = %w[
|
@@ -26,14 +27,13 @@ module CodeRay
|
|
26
27
|
add(PREDEFINED_CONSTANTS, :predefined_constant)
|
27
28
|
|
28
29
|
KEYWORD_NEXT_TOKEN_KIND = WordList.new(nil).
|
29
|
-
add(%w[ def
|
30
|
-
add(%w[
|
31
|
-
add(%w[ defprotocol defrecord ], :class)
|
30
|
+
add(%w[ def ], :function).
|
31
|
+
add(%w[ class ], :class)
|
32
32
|
|
33
33
|
BASIC_IDENTIFIER = /[a-zA-Z$%*\/_+!?&<>\-=]=?[a-zA-Z0-9$&*+!\/_?<>\-\#]*/
|
34
34
|
CLASS_IDENTIFIER = /[A-Z]+[A-Za-z0-9]*|[A-Z]+[A-Za-z0-9]\:\:|\:\:[A-Z]+[A-Za-z0-9]*/
|
35
35
|
IDENTIFIER = /(?!-\d)(?:(?:#{BASIC_IDENTIFIER}\.)*#{BASIC_IDENTIFIER}(?:\/#{BASIC_IDENTIFIER})?\.?)|\.\.?/
|
36
|
-
SYMBOL = /\'[A-
|
36
|
+
SYMBOL = /\'[A-z0-9\:\!\%\^\&\*\_\-\+\=\|\?\\\/\>\<\~\.]+/o
|
37
37
|
DIGIT = /\d+/
|
38
38
|
DIGIT10 = DIGIT
|
39
39
|
DIGIT16 = /[0-9a-f]/i
|
data/tests/block.fy
CHANGED
@@ -359,26 +359,24 @@ FancySpec describe: Block with: {
|
|
359
359
|
a is: [2,1,2,1]
|
360
360
|
}
|
361
361
|
|
362
|
-
it: "calls itself while logging errors to *
|
362
|
+
it: "calls itself while logging errors to *stderr*" with: 'call_with_errors_logged when: {
|
363
363
|
io = StringIO new
|
364
|
-
let: '*
|
364
|
+
let: '*stderr* be: io in: {
|
365
365
|
{
|
366
|
-
"hello" println
|
367
366
|
2 / 0
|
368
367
|
} call_with_errors_logged
|
369
368
|
}
|
370
|
-
io string is: "
|
369
|
+
io string is: "divided by 0\n"
|
371
370
|
}
|
372
371
|
|
373
|
-
it: "calls itself with arguments while logging errors to *
|
372
|
+
it: "calls itself with arguments while logging errors to *stderr*" with: 'call_with_errors_logged: when: {
|
374
373
|
io = StringIO new
|
375
|
-
let: '*
|
374
|
+
let: '*stderr* be: io in: {
|
376
375
|
|x y| {
|
377
|
-
"x: #{x} y: #{y}" println
|
378
376
|
2 / 0
|
379
377
|
} call_with_errors_logged: [10, 20]
|
380
378
|
}
|
381
|
-
io string is: "
|
379
|
+
io string is: "divided by 0\n"
|
382
380
|
}
|
383
381
|
|
384
382
|
it: "calls itself while logging errors to a given IO object" with: 'call_with_errors_logged_to: when: {
|
@@ -389,16 +387,41 @@ FancySpec describe: Block with: {
|
|
389
387
|
io string is: "divided by 0\n"
|
390
388
|
|
391
389
|
io = StringIO new
|
392
|
-
{
|
390
|
+
{
|
391
|
+
{ "fail!" raise! } call_with_errors_logged_to: io
|
392
|
+
} does_not raise: StandardError
|
393
|
+
io string is: "fail!\n"
|
394
|
+
}
|
395
|
+
|
396
|
+
it: "calls itself while logging errors to a given IO object and reraising exceptions" with: 'call_with_errors_logged_to:reraise: when: {
|
397
|
+
io = StringIO new
|
398
|
+
{
|
399
|
+
{
|
400
|
+
"fail!" raise!
|
401
|
+
} call_with_errors_logged_to: io reraise: true
|
402
|
+
} raises: StandardError
|
393
403
|
io string is: "fail!\n"
|
394
404
|
}
|
395
405
|
|
396
406
|
it: "calls itself with arguments while logging errors to a given IO object" with: 'call:with_errors_logged_to: when: {
|
397
407
|
io = StringIO new
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
408
|
+
{
|
409
|
+
|x y| {
|
410
|
+
io println: "x: #{x} y: #{y}"
|
411
|
+
2 / 0
|
412
|
+
} call: [10, 20] with_errors_logged_to: io
|
413
|
+
} does_not raise: ZeroDivisionError
|
414
|
+
io string is: "x: 10 y: 20\ndivided by 0\n"
|
415
|
+
}
|
416
|
+
|
417
|
+
it: "calls itself with arguments while logging errors to a given IO object and reraising exceptions" with: 'call:with_errors_logged_to:reraise: when: {
|
418
|
+
io = StringIO new
|
419
|
+
{
|
420
|
+
|x y| {
|
421
|
+
io println: "x: #{x} y: #{y}"
|
422
|
+
2 / 0
|
423
|
+
} call: [10, 20] with_errors_logged_to: io reraise: true
|
424
|
+
} raises: ZeroDivisionError
|
402
425
|
io string is: "x: 10 y: 20\ndivided by 0\n"
|
403
426
|
}
|
404
427
|
}
|
data/tests/class.fy
CHANGED
@@ -36,6 +36,8 @@ class ClassWithPrivate {
|
|
36
36
|
private: 'private_method
|
37
37
|
}
|
38
38
|
|
39
|
+
require: "stringio"
|
40
|
+
|
39
41
|
FancySpec describe: Class with: {
|
40
42
|
it: "does NOT find the method when not mixed-in" with: 'responds_to?: when: {
|
41
43
|
instance = ClassWithMixin new
|
@@ -208,7 +210,8 @@ FancySpec describe: Class with: {
|
|
208
210
|
Symbol superclass is: Object
|
209
211
|
StdError superclass is: Exception
|
210
212
|
Class superclass is: Module
|
211
|
-
Object superclass is:
|
213
|
+
Object superclass is: BasicObject
|
214
|
+
BasicObject superclass is: nil
|
212
215
|
|
213
216
|
IOError superclass is: StandardError
|
214
217
|
NoMethodError superclass is: NameError
|
@@ -438,7 +441,7 @@ FancySpec describe: Class with: {
|
|
438
441
|
try {
|
439
442
|
[] equal?: [1,2] . is: true # is fail
|
440
443
|
} catch NoMethodError => e {
|
441
|
-
e
|
444
|
+
e message does =~ /equal\?:/
|
442
445
|
}
|
443
446
|
|
444
447
|
class Array {
|
@@ -453,9 +456,9 @@ FancySpec describe: Class with: {
|
|
453
456
|
class B : A
|
454
457
|
class C : B
|
455
458
|
|
456
|
-
A ancestors is: [A, Object, Kernel]
|
457
|
-
B ancestors is: [B, A, Object, Kernel]
|
458
|
-
C ancestors is: [C, B, A, Object, Kernel]
|
459
|
+
A ancestors is: [A, Object, Kernel, BasicObject]
|
460
|
+
B ancestors is: [B, A, Object, Kernel, BasicObject]
|
461
|
+
C ancestors is: [C, B, A, Object, Kernel, BasicObject]
|
459
462
|
}
|
460
463
|
|
461
464
|
it: "makes methods private" with: 'private: when: {
|
@@ -605,7 +608,7 @@ FancySpec describe: Class with: {
|
|
605
608
|
}
|
606
609
|
|
607
610
|
it: "returns its nested constants" with: 'constants when: {
|
608
|
-
WithConstants constants =? [
|
611
|
+
WithConstants constants =? ['Foo, 'Bar, 'Nested] is: true
|
609
612
|
}
|
610
613
|
|
611
614
|
it: "returns a constants value" with: '[] when: {
|
@@ -684,7 +687,8 @@ FancySpec describe: Class with: {
|
|
684
687
|
Fixnum inspect is: "Fixnum : Integer"
|
685
688
|
MySuperClass inspect is: "MySuperClass : Object"
|
686
689
|
MySubClass inspect is: "MySubClass : MySuperClass"
|
687
|
-
Object inspect is: "Object"
|
690
|
+
Object inspect is: "Object : BasicObject"
|
691
|
+
BasicObject inspect is: "BasicObject"
|
688
692
|
}
|
689
693
|
|
690
694
|
it: "returns the right amount of instance methods" with: 'instance_methods: when: {
|
@@ -700,156 +704,156 @@ FancySpec describe: Class with: {
|
|
700
704
|
Set[OneMethod instance_methods] is: $ Set[Object instance_methods + (OneMethod instance_methods: false)]
|
701
705
|
}
|
702
706
|
|
703
|
-
it: "defines a before_method handler" with: 'before_method:run: when: {
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
707
|
+
# it: "defines a before_method handler" with: 'before_method:run: when: {
|
708
|
+
# class BeforeMethodClass {
|
709
|
+
# read_slot: 'x
|
710
|
+
# def initialize: @x
|
711
|
+
# def before: arr {
|
712
|
+
# arr << "Before Method: #{@x}"
|
713
|
+
# }
|
714
|
+
# def my_method: arr {
|
715
|
+
# arr << "My Method: #{@x}"
|
716
|
+
# }
|
713
717
|
|
714
|
-
|
715
|
-
|
718
|
+
# before_method: 'my_method: run: 'before:
|
719
|
+
# }
|
716
720
|
|
717
|
-
|
718
|
-
|
721
|
+
# b1 = BeforeMethodClass new: 1
|
722
|
+
# b2 = BeforeMethodClass new: 2
|
719
723
|
|
720
|
-
|
724
|
+
# array = []
|
721
725
|
|
722
|
-
|
723
|
-
|
726
|
+
# b1 my_method: array
|
727
|
+
# b2 my_method: array
|
724
728
|
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
+
# array is: [
|
730
|
+
# "Before Method: 1", "My Method: 1",
|
731
|
+
# "Before Method: 2", "My Method: 2"
|
732
|
+
# ]
|
729
733
|
|
730
|
-
|
734
|
+
# # we can also pass blocks
|
731
735
|
|
732
|
-
|
733
|
-
|
734
|
-
|
736
|
+
# BeforeMethodClass before_method: 'my_method: run: |receiver array| {
|
737
|
+
# array << "Before Block: #{receiver x}"
|
738
|
+
# }
|
735
739
|
|
736
|
-
|
740
|
+
# array = []
|
737
741
|
|
738
|
-
|
739
|
-
|
742
|
+
# b1 my_method: array
|
743
|
+
# b2 my_method: array
|
740
744
|
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
}
|
745
|
+
# array is: [
|
746
|
+
# "Before Block: 1", "Before Method: 1", "My Method: 1",
|
747
|
+
# "Before Block: 2", "Before Method: 2", "My Method: 2"
|
748
|
+
# ]
|
749
|
+
# }
|
746
750
|
|
747
|
-
it: "defines an after_method handler" with: 'after_method:run: when: {
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
751
|
+
# it: "defines an after_method handler" with: 'after_method:run: when: {
|
752
|
+
# class AfterMethodClass {
|
753
|
+
# read_slot: 'x
|
754
|
+
# def initialize: @x
|
755
|
+
# def after: arr {
|
756
|
+
# arr << "After Method: #{@x}"
|
757
|
+
# }
|
758
|
+
# def my_method: arr {
|
759
|
+
# arr << "My Method: #{@x}"
|
760
|
+
# }
|
757
761
|
|
758
|
-
|
759
|
-
|
762
|
+
# after_method: 'my_method: run: 'after:
|
763
|
+
# }
|
760
764
|
|
761
|
-
|
762
|
-
|
765
|
+
# b1 = AfterMethodClass new: 1
|
766
|
+
# b2 = AfterMethodClass new: 2
|
763
767
|
|
764
|
-
|
768
|
+
# array = []
|
765
769
|
|
766
|
-
|
767
|
-
|
770
|
+
# b1 my_method: array
|
771
|
+
# b2 my_method: array
|
768
772
|
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
+
# array is: [
|
774
|
+
# "My Method: 1", "After Method: 1",
|
775
|
+
# "My Method: 2", "After Method: 2"
|
776
|
+
# ]
|
773
777
|
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
+
# AfterMethodClass after_method: 'my_method: run: |receiver array| {
|
779
|
+
# "block getting called yo"
|
780
|
+
# array << "After Block: #{receiver x}"
|
781
|
+
# }
|
778
782
|
|
779
|
-
|
783
|
+
# array = []
|
780
784
|
|
781
|
-
|
782
|
-
|
785
|
+
# b1 my_method: array
|
786
|
+
# b2 my_method: array
|
783
787
|
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
}
|
788
|
+
# array is: [
|
789
|
+
# "My Method: 1", "After Method: 1", "After Block: 1",
|
790
|
+
# "My Method: 2", "After Method: 2", "After Block: 2"
|
791
|
+
# ]
|
792
|
+
# }
|
789
793
|
|
790
794
|
|
791
|
-
it: "defines an around_method handler" with: 'around_method:run: when: {
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
795
|
+
# it: "defines an around_method handler" with: 'around_method:run: when: {
|
796
|
+
# class AroundMethodClass {
|
797
|
+
# read_slot: 'x
|
798
|
+
# def initialize: @x
|
799
|
+
# def around: arr {
|
800
|
+
# arr << "Around Method: #{@x}"
|
801
|
+
# }
|
802
|
+
# def my_method: arr {
|
803
|
+
# arr << "My Method: #{@x}"
|
804
|
+
# }
|
801
805
|
|
802
|
-
|
803
|
-
|
806
|
+
# around_method: 'my_method: run: 'around:
|
807
|
+
# }
|
804
808
|
|
805
|
-
|
806
|
-
|
809
|
+
# b1 = AroundMethodClass new: 1
|
810
|
+
# b2 = AroundMethodClass new: 2
|
807
811
|
|
808
|
-
|
812
|
+
# array = []
|
809
813
|
|
810
|
-
|
811
|
-
|
814
|
+
# b1 my_method: array
|
815
|
+
# b2 my_method: array
|
812
816
|
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
+
# array is: [
|
818
|
+
# "Around Method: 1", "My Method: 1", "Around Method: 1",
|
819
|
+
# "Around Method: 2", "My Method: 2", "Around Method: 2"
|
820
|
+
# ]
|
817
821
|
|
818
822
|
|
819
|
-
|
820
|
-
|
821
|
-
|
823
|
+
# AroundMethodClass around_method: 'my_method: run: |receiver array| {
|
824
|
+
# array << "Around Block: #{receiver x}"
|
825
|
+
# }
|
822
826
|
|
823
|
-
|
827
|
+
# array = []
|
824
828
|
|
825
|
-
|
826
|
-
|
829
|
+
# b1 my_method: array
|
830
|
+
# b2 my_method: array
|
827
831
|
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
}
|
832
|
+
# array is: [
|
833
|
+
# "Around Block: 1", "Around Method: 1", "My Method: 1", "Around Method: 1", "Around Block: 1",
|
834
|
+
# "Around Block: 2", "Around Method: 2", "My Method: 2", "Around Method: 2", "Around Block: 2"
|
835
|
+
# ]
|
836
|
+
# }
|
833
837
|
|
834
|
-
it: "defines a custom calling chain for a method" with: 'define_calling_chain:for_method: when: {
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
838
|
+
# it: "defines a custom calling chain for a method" with: 'define_calling_chain:for_method: when: {
|
839
|
+
# class CallingChainClass {
|
840
|
+
# def foo: arr { arr << "foo" }
|
841
|
+
# def bar: arr { arr << "bar" }
|
842
|
+
# def baz: arr { arr << "baz" }
|
839
843
|
|
840
|
-
|
841
|
-
|
844
|
+
# define_calling_chain: ('foo:, 'bar:, 'baz:) for_method: 'foo:
|
845
|
+
# }
|
842
846
|
|
843
|
-
|
844
|
-
|
845
|
-
|
847
|
+
# arr = []
|
848
|
+
# CallingChainClass new foo: arr
|
849
|
+
# arr is: ["foo", "bar", "baz"]
|
846
850
|
|
847
|
-
|
851
|
+
# CallingChainClass define_calling_chain: [|receiver arr|{ receiver baz: arr }, 'bar:] for_method: 'bar:
|
848
852
|
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
}
|
853
|
+
# arr = []
|
854
|
+
# CallingChainClass new bar: arr
|
855
|
+
# arr is: ["baz", "bar"]
|
856
|
+
# }
|
853
857
|
|
854
858
|
it: "exposes a Fancy method as a Ruby method to Ruby" with: 'expose_to_ruby:as: when: {
|
855
859
|
class ExposeToRuby {
|