code-ruby 4.0.0 → 4.0.1
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/code +8 -5
- data/lib/code/concerns/shared.rb +102 -98
- data/lib/code/format.rb +23 -19
- data/lib/code/network.rb +23 -28
- data/lib/code/node/call.rb +9 -8
- data/lib/code/node/code.rb +1 -1
- data/lib/code/node/list.rb +10 -8
- data/lib/code/node/square_bracket.rb +4 -2
- data/lib/code/object/boolean.rb +13 -17
- data/lib/code/object/class.rb +32 -27
- data/lib/code/object/code.rb +2 -9
- data/lib/code/object/context.rb +4 -2
- data/lib/code/object/cryptography.rb +12 -6
- data/lib/code/object/date.rb +910 -449
- data/lib/code/object/decimal.rb +229 -856
- data/lib/code/object/dictionary.rb +113 -42
- data/lib/code/object/duration.rb +3 -7
- data/lib/code/object/function.rb +64 -40
- data/lib/code/object/global.rb +121 -208
- data/lib/code/object/html.rb +4 -2
- data/lib/code/object/http.rb +32 -26
- data/lib/code/object/ics.rb +2 -1
- data/lib/code/object/identifier_list.rb +16 -11
- data/lib/code/object/integer.rb +270 -942
- data/lib/code/object/json.rb +8 -3
- data/lib/code/object/list.rb +97 -109
- data/lib/code/object/nothing.rb +11 -11
- data/lib/code/object/number.rb +20 -10
- data/lib/code/object/parameter.rb +18 -9
- data/lib/code/object/range.rb +62 -108
- data/lib/code/object/smtp.rb +20 -12
- data/lib/code/object/string.rb +52 -28
- data/lib/code/object/super.rb +2 -1
- data/lib/code/object/time.rb +1146 -572
- data/lib/code/object/url.rb +4 -2
- data/lib/code/object.rb +119 -80
- data/lib/code/parser.rb +34 -32
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 04a1a64dae9f86bb218f016da7f56a7d4358d4dc63c620132ce58dd0a8d96b7d
|
|
4
|
+
data.tar.gz: 3735d10e82af9370ed1c4cff86e5c3965678a7b22e3a5ea709f11eda601d49b7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d3c2288da223c047a41c6f6f30eba9c22c4e3ec7e4b058390530c0036a20d42580ce4755620345c4ff2c8403c0ffd9381d3a4865f690aedc2e4483617c695852
|
|
7
|
+
data.tar.gz: f21b89e07ec4f156d8ed3eec697902da23cd6dc269a74eeee375a7cc06b83bd78f22d8dee9613a10e9546908379f1128d75f104549d5c16650d81849e08f94b0
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
4.0.
|
|
1
|
+
4.0.1
|
data/bin/code
CHANGED
|
@@ -95,16 +95,17 @@ def expand_arguments(arguments)
|
|
|
95
95
|
remaining_arguments << argument
|
|
96
96
|
end
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
if expanded_files.size > MAX_ARGUMENT_FILES
|
|
99
|
+
raise Code::Error, "too many input files"
|
|
100
|
+
end
|
|
99
101
|
end
|
|
100
102
|
|
|
101
103
|
[expanded_files, remaining_arguments]
|
|
102
104
|
end
|
|
103
105
|
|
|
104
106
|
begin
|
|
105
|
-
@parsed_timeout =
|
|
106
|
-
parsed.options.timeout || Code::DEFAULT_TIMEOUT
|
|
107
|
-
)
|
|
107
|
+
@parsed_timeout =
|
|
108
|
+
Code.normalize_timeout!(parsed.options.timeout || Code::DEFAULT_TIMEOUT)
|
|
108
109
|
rescue Code::Error => e
|
|
109
110
|
abort "#{e.class}: #{e.message}"
|
|
110
111
|
end
|
|
@@ -126,7 +127,9 @@ begin
|
|
|
126
127
|
append_limited(buffer, remaining_arguments.join(" "))
|
|
127
128
|
|
|
128
129
|
input_files = parsed.files + expanded_argument_files
|
|
129
|
-
|
|
130
|
+
if input_files.size > MAX_ARGUMENT_FILES
|
|
131
|
+
raise Code::Error, "too many input files"
|
|
132
|
+
end
|
|
130
133
|
|
|
131
134
|
input_files.each.with_index do |file, index|
|
|
132
135
|
append_limited(buffer, "\n\n") if index.positive?
|
data/lib/code/concerns/shared.rb
CHANGED
|
@@ -5,96 +5,96 @@ class Code
|
|
|
5
5
|
module Shared
|
|
6
6
|
attr_accessor :raw, :functions
|
|
7
7
|
|
|
8
|
-
COMPOUND_ASSIGNMENT_OPERATORS = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
COMPOUND_ASSIGNMENT_OPERATORS = %w[
|
|
9
|
+
+=
|
|
10
|
+
-=
|
|
11
|
+
*=
|
|
12
|
+
/=
|
|
13
|
+
%=
|
|
14
|
+
<<=
|
|
15
|
+
>>=
|
|
16
|
+
&=
|
|
17
|
+
|=
|
|
18
|
+
^=
|
|
19
|
+
||=
|
|
20
|
+
&&=
|
|
21
21
|
].freeze
|
|
22
|
-
SHARED_OPERATORS = [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
22
|
+
SHARED_OPERATORS = %w[
|
|
23
|
+
documentation
|
|
24
|
+
present?
|
|
25
|
+
blank?
|
|
26
|
+
presence
|
|
27
|
+
presence_in
|
|
28
|
+
is_a?
|
|
29
|
+
is_an?
|
|
30
|
+
kind_of?
|
|
31
|
+
instance_of?
|
|
32
|
+
new
|
|
33
|
+
!
|
|
34
|
+
not
|
|
35
|
+
!=
|
|
36
|
+
different
|
|
37
|
+
&&
|
|
38
|
+
and
|
|
39
|
+
+
|
|
40
|
+
self
|
|
41
|
+
..
|
|
42
|
+
inclusive_range
|
|
43
|
+
...
|
|
44
|
+
exclusive_range
|
|
45
|
+
==
|
|
46
|
+
equal
|
|
47
|
+
equal?
|
|
48
|
+
same_object?
|
|
49
|
+
>
|
|
50
|
+
greater
|
|
51
|
+
>=
|
|
52
|
+
greater_or_equal
|
|
53
|
+
<=>
|
|
54
|
+
compare
|
|
55
|
+
<
|
|
56
|
+
less
|
|
57
|
+
<=
|
|
58
|
+
less_or_equal
|
|
59
|
+
===
|
|
60
|
+
strict_equal
|
|
61
|
+
!==
|
|
62
|
+
strict_different
|
|
63
|
+
falsy?
|
|
64
|
+
truthy?
|
|
65
|
+
true?
|
|
66
|
+
false?
|
|
67
|
+
||
|
|
68
|
+
or
|
|
69
|
+
to_boolean
|
|
70
|
+
to_class
|
|
71
|
+
to_date
|
|
72
|
+
to_decimal
|
|
73
|
+
to_dictionary
|
|
74
|
+
to_duration
|
|
75
|
+
to_integer
|
|
76
|
+
to_list
|
|
77
|
+
to_nothing
|
|
78
|
+
to_range
|
|
79
|
+
to_string
|
|
80
|
+
inspect
|
|
81
|
+
to_time
|
|
82
|
+
as_json
|
|
83
|
+
duplicate
|
|
84
|
+
deep_duplicate
|
|
85
|
+
to_parameter
|
|
86
|
+
to_json
|
|
87
|
+
functions
|
|
88
|
+
instance_functions
|
|
89
|
+
class_functions
|
|
90
|
+
respond_to?
|
|
91
|
+
send
|
|
92
|
+
itself
|
|
93
|
+
tap
|
|
94
|
+
then
|
|
95
|
+
name
|
|
96
|
+
nothing?
|
|
97
|
+
something?
|
|
98
98
|
].freeze
|
|
99
99
|
OPERATOR_METHOD_ALIASES = {
|
|
100
100
|
"[]" => "get",
|
|
@@ -519,7 +519,9 @@ class Code
|
|
|
519
519
|
return nil unless code_dynamic_functions.code_has_key?(operator).truthy?
|
|
520
520
|
|
|
521
521
|
stored_value = code_dynamic_functions.code_fetch(operator)
|
|
522
|
-
|
|
522
|
+
if stored_value.is_a?(Object::Function)
|
|
523
|
+
return stored_value.call(**args, operator: nil, bound_self: self)
|
|
524
|
+
end
|
|
523
525
|
|
|
524
526
|
sig(args)
|
|
525
527
|
stored_value
|
|
@@ -641,9 +643,10 @@ class Code
|
|
|
641
643
|
|
|
642
644
|
def code_instance_functions
|
|
643
645
|
Object.sorted_dictionary(
|
|
644
|
-
Object
|
|
645
|
-
|
|
646
|
-
|
|
646
|
+
Object
|
|
647
|
+
.documented_functions_for(self.class, :instance)
|
|
648
|
+
.code_merge(dynamic_functions_documentation)
|
|
649
|
+
.raw
|
|
647
650
|
)
|
|
648
651
|
end
|
|
649
652
|
|
|
@@ -755,7 +758,8 @@ class Code
|
|
|
755
758
|
end
|
|
756
759
|
|
|
757
760
|
def code_operator_method_defined?(operator_name)
|
|
758
|
-
method_name =
|
|
761
|
+
method_name =
|
|
762
|
+
:"code_#{OPERATOR_METHOD_ALIASES.fetch(operator_name, operator_name)}"
|
|
759
763
|
return false unless respond_to?(method_name)
|
|
760
764
|
|
|
761
765
|
method(method_name).owner != Shared
|
|
@@ -775,10 +779,10 @@ class Code
|
|
|
775
779
|
name,
|
|
776
780
|
Object::Dictionary.new(
|
|
777
781
|
"name" => Object::String.new(name),
|
|
778
|
-
"description" =>
|
|
779
|
-
dynamic_function_description(value)
|
|
780
|
-
|
|
781
|
-
|
|
782
|
+
"description" =>
|
|
783
|
+
Object::String.new(dynamic_function_description(value)),
|
|
784
|
+
"examples" =>
|
|
785
|
+
Object::List.new(dynamic_function_examples(value)),
|
|
782
786
|
"function" => value
|
|
783
787
|
)
|
|
784
788
|
]
|
data/lib/code/format.rb
CHANGED
|
@@ -207,10 +207,7 @@ class Code
|
|
|
207
207
|
end
|
|
208
208
|
|
|
209
209
|
def escape_string_text(text)
|
|
210
|
-
text
|
|
211
|
-
.gsub("\\", "\\\\")
|
|
212
|
-
.gsub('"', '\"')
|
|
213
|
-
.gsub("{", "\\{")
|
|
210
|
+
text.gsub("\\", "\\\\").gsub('"', '\"').gsub("{", "\\{")
|
|
214
211
|
end
|
|
215
212
|
|
|
216
213
|
def format_string_literal(content, components:, indent:, allow_split:)
|
|
@@ -335,7 +332,7 @@ class Code
|
|
|
335
332
|
def format_dictionary_statement_code(statement_code)
|
|
336
333
|
key =
|
|
337
334
|
format_dictionary_statement_key(statement_code[:statement]) ||
|
|
338
|
-
|
|
335
|
+
format_nested_statement(statement_code[:statement], indent: 0)
|
|
339
336
|
return key unless statement_code.key?(:code)
|
|
340
337
|
|
|
341
338
|
value = format_code_inline(statement_code[:code], indent: 0)
|
|
@@ -477,14 +474,17 @@ class Code
|
|
|
477
474
|
first_line, *rest = right.lines(chomp: true)
|
|
478
475
|
if multiline_operand_statement?(other[:statement]) ||
|
|
479
476
|
!BOOLEAN_WORD_OPERATORS.include?(operator)
|
|
480
|
-
["#{expression} #{operator} #{first_line.lstrip}", *rest].join(
|
|
477
|
+
["#{expression} #{operator} #{first_line.lstrip}", *rest].join(
|
|
478
|
+
"\n"
|
|
479
|
+
)
|
|
481
480
|
else
|
|
482
481
|
[
|
|
483
482
|
"#{expression}\n#{INDENT * (indent + 1)}#{operator} #{first_line.lstrip}",
|
|
484
483
|
*rest
|
|
485
484
|
].join("\n")
|
|
486
485
|
end
|
|
487
|
-
elsif expression.include?("\n") ||
|
|
486
|
+
elsif expression.include?("\n") ||
|
|
487
|
+
candidate.length > MAX_LINE_LENGTH
|
|
488
488
|
right_lines =
|
|
489
489
|
if right.include?("\n")
|
|
490
490
|
right.lines(chomp: true).map(&:lstrip)
|
|
@@ -521,10 +521,9 @@ class Code
|
|
|
521
521
|
return false if expression.lstrip.start_with?("(")
|
|
522
522
|
|
|
523
523
|
continuation_lines =
|
|
524
|
-
expression
|
|
525
|
-
.
|
|
526
|
-
|
|
527
|
-
.reject { |line| line.strip.empty? || line.strip.match?(/\A[\])}]+\z/) }
|
|
524
|
+
expression.lines(chomp: true)[1..].to_a.reject do |line|
|
|
525
|
+
line.strip.empty? || line.strip.match?(/\A[\])}]+\z/)
|
|
526
|
+
end
|
|
528
527
|
|
|
529
528
|
return false if continuation_lines.empty?
|
|
530
529
|
|
|
@@ -578,10 +577,7 @@ class Code
|
|
|
578
577
|
first_line = first_line.lstrip
|
|
579
578
|
return "#{left} #{operator} #{first_line}" if rest.empty?
|
|
580
579
|
|
|
581
|
-
return [
|
|
582
|
-
"#{left} #{operator} #{first_line}",
|
|
583
|
-
*rest
|
|
584
|
-
].join("\n")
|
|
580
|
+
return ["#{left} #{operator} #{first_line}", *rest].join("\n")
|
|
585
581
|
end
|
|
586
582
|
|
|
587
583
|
"#{left} #{operator} #{right}"
|
|
@@ -594,7 +590,9 @@ class Code
|
|
|
594
590
|
if nested_operator == "="
|
|
595
591
|
left = format_nested_statement(nested[:left], indent: indent)
|
|
596
592
|
right = format_nested_statement(nested[:right], indent: indent)
|
|
597
|
-
return
|
|
593
|
+
return(
|
|
594
|
+
"#{left} #{nested_operator} #{group_multiline_expression(right, indent: indent)}"
|
|
595
|
+
)
|
|
598
596
|
end
|
|
599
597
|
end
|
|
600
598
|
|
|
@@ -724,7 +722,8 @@ class Code
|
|
|
724
722
|
Array(while_statement[:parameters]).map do |parameter|
|
|
725
723
|
format_parameter(parameter, indent: indent)
|
|
726
724
|
end
|
|
727
|
-
header =
|
|
725
|
+
header =
|
|
726
|
+
parameters.empty? ? "loop {" : "loop { |#{parameters.join(", ")}|"
|
|
728
727
|
|
|
729
728
|
return "#{INDENT * indent}#{header}\n#{body}\n#{INDENT * indent}}"
|
|
730
729
|
end
|
|
@@ -757,7 +756,9 @@ class Code
|
|
|
757
756
|
others = Array(operation[:others])
|
|
758
757
|
|
|
759
758
|
return false if others.empty?
|
|
760
|
-
|
|
759
|
+
unless others.all? { |other| compact_operator?(other[:operator]) }
|
|
760
|
+
return false
|
|
761
|
+
end
|
|
761
762
|
|
|
762
763
|
return multiline_operand_statement?(operation[:first])
|
|
763
764
|
end
|
|
@@ -785,7 +786,10 @@ class Code
|
|
|
785
786
|
|
|
786
787
|
def indent_lines(value, indent)
|
|
787
788
|
prefix = INDENT * indent
|
|
788
|
-
value
|
|
789
|
+
value
|
|
790
|
+
.split("\n")
|
|
791
|
+
.map { |line| line.empty? ? "" : "#{prefix}#{line}" }
|
|
792
|
+
.join("\n")
|
|
789
793
|
end
|
|
790
794
|
|
|
791
795
|
def statement_separator(inline:, indent: nil)
|
data/lib/code/network.rb
CHANGED
|
@@ -2,34 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
class Code
|
|
4
4
|
module Network
|
|
5
|
-
BLOCKED_HOSTS = %w[
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"2002::/16",
|
|
29
|
-
"fc00::/7",
|
|
30
|
-
"fe80::/10",
|
|
31
|
-
"ff00::/8"
|
|
32
|
-
].map { |range| IPAddr.new(range) }.freeze
|
|
5
|
+
BLOCKED_HOSTS = %w[localhost localhost.localdomain].freeze
|
|
6
|
+
BLOCKED_HOST_SUFFIXES = %w[.local .localhost].freeze
|
|
7
|
+
BLOCKED_IP_RANGES =
|
|
8
|
+
%w[
|
|
9
|
+
0.0.0.0/8
|
|
10
|
+
10.0.0.0/8
|
|
11
|
+
100.64.0.0/10
|
|
12
|
+
127.0.0.0/8
|
|
13
|
+
169.254.0.0/16
|
|
14
|
+
172.16.0.0/12
|
|
15
|
+
192.0.0.0/24
|
|
16
|
+
192.168.0.0/16
|
|
17
|
+
224.0.0.0/4
|
|
18
|
+
240.0.0.0/4
|
|
19
|
+
::/128
|
|
20
|
+
::1/128
|
|
21
|
+
64:ff9b::/96
|
|
22
|
+
64:ff9b:1::/48
|
|
23
|
+
2002::/16
|
|
24
|
+
fc00::/7
|
|
25
|
+
fe80::/10
|
|
26
|
+
ff00::/8
|
|
27
|
+
].map { |range| IPAddr.new(range) }.freeze
|
|
33
28
|
|
|
34
29
|
def self.validate_public_uri!(uri, service:)
|
|
35
30
|
unless %w[http https].include?(uri.scheme)
|
data/lib/code/node/call.rb
CHANGED
|
@@ -54,13 +54,14 @@ class Code
|
|
|
54
54
|
name = Object::String.new(@name)
|
|
55
55
|
|
|
56
56
|
object = args.fetch(:object)
|
|
57
|
-
dynamic_result =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
dynamic_result =
|
|
58
|
+
object.code_dynamic_call(
|
|
59
|
+
name,
|
|
60
|
+
operator: name,
|
|
61
|
+
arguments: Object::List.new(arguments),
|
|
62
|
+
explicit_arguments: @explicit_arguments,
|
|
63
|
+
**args
|
|
64
|
+
)
|
|
64
65
|
return dynamic_result if dynamic_result
|
|
65
66
|
|
|
66
67
|
object.call(
|
|
@@ -99,7 +100,7 @@ class Code
|
|
|
99
100
|
when "&"
|
|
100
101
|
code_value = value.to_code
|
|
101
102
|
arguments << if code_value.is_a?(Object::Function) ||
|
|
102
|
-
|
|
103
|
+
code_value.nothing?
|
|
103
104
|
code_value
|
|
104
105
|
else
|
|
105
106
|
code_value.call(operator: "&", **args)
|
data/lib/code/node/code.rb
CHANGED
data/lib/code/node/list.rb
CHANGED
|
@@ -11,20 +11,22 @@ class Code
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def evaluate(**args)
|
|
14
|
-
list =
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
list =
|
|
15
|
+
::Code::Object::List.new(
|
|
16
|
+
(@elements || []).map { |element| element.evaluate(**args) }
|
|
17
|
+
)
|
|
17
18
|
constructor = literal_constructor(args.fetch(:context), "List")
|
|
18
19
|
return list unless constructor
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
if Array(args[:constructing_literal_classes]).include?(
|
|
21
|
+
::Code::Object::List
|
|
22
|
+
)
|
|
23
|
+
return list
|
|
24
|
+
end
|
|
22
25
|
|
|
23
26
|
constructor.call(
|
|
24
27
|
**args,
|
|
25
28
|
constructing_literal_classes:
|
|
26
|
-
Array(args[:constructing_literal_classes]) +
|
|
27
|
-
[::Code::Object::List],
|
|
29
|
+
Array(args[:constructing_literal_classes]) + [::Code::Object::List],
|
|
28
30
|
operator: nil,
|
|
29
31
|
arguments: ::Code::Object::List.new([list]),
|
|
30
32
|
explicit_arguments: true
|
|
@@ -13,7 +13,8 @@ class Code
|
|
|
13
13
|
|
|
14
14
|
def evaluate(**args)
|
|
15
15
|
left = @left&.evaluate(**args) || Object::Nothing.new
|
|
16
|
-
index_args =
|
|
16
|
+
index_args =
|
|
17
|
+
args.merge(object: args.fetch(:previous_object, args.fetch(:object)))
|
|
17
18
|
|
|
18
19
|
(@statements || []).reduce(left) do |object, statement|
|
|
19
20
|
object.code_fetch(statement.evaluate(**index_args))
|
|
@@ -30,7 +31,8 @@ class Code
|
|
|
30
31
|
Object::IdentifierList.new([left])
|
|
31
32
|
end
|
|
32
33
|
|
|
33
|
-
index_args =
|
|
34
|
+
index_args =
|
|
35
|
+
args.merge(object: args.fetch(:previous_object, args.fetch(:object)))
|
|
34
36
|
|
|
35
37
|
(@statements || []).each do |statement|
|
|
36
38
|
list.code_append(statement.evaluate(**index_args))
|
data/lib/code/object/boolean.rb
CHANGED
|
@@ -6,11 +6,7 @@ class Code
|
|
|
6
6
|
CLASS_DOCUMENTATION = {
|
|
7
7
|
name: "Boolean",
|
|
8
8
|
description: "represents true or false.",
|
|
9
|
-
examples: [
|
|
10
|
-
"Boolean",
|
|
11
|
-
"Boolean.new(true)",
|
|
12
|
-
"Boolean.new(false)"
|
|
13
|
-
]
|
|
9
|
+
examples: %w[Boolean Boolean.new(true) Boolean.new(false)]
|
|
14
10
|
}.freeze
|
|
15
11
|
INSTANCE_FUNCTIONS = {
|
|
16
12
|
"&" => {
|
|
@@ -21,10 +17,10 @@ class Code
|
|
|
21
17
|
"bitwise_and" => {
|
|
22
18
|
name: "bitwise_and",
|
|
23
19
|
description: "returns true when both booleans are true.",
|
|
24
|
-
examples: [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
examples: %w[
|
|
21
|
+
true.bitwise_and(true)
|
|
22
|
+
true.bitwise_and(false)
|
|
23
|
+
false.bitwise_and(false)
|
|
28
24
|
]
|
|
29
25
|
},
|
|
30
26
|
"|" => {
|
|
@@ -35,10 +31,10 @@ class Code
|
|
|
35
31
|
"bitwise_or" => {
|
|
36
32
|
name: "bitwise_or",
|
|
37
33
|
description: "returns true when either boolean is true.",
|
|
38
|
-
examples: [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
examples: %w[
|
|
35
|
+
true.bitwise_or(false)
|
|
36
|
+
false.bitwise_or(true)
|
|
37
|
+
false.bitwise_or(false)
|
|
42
38
|
]
|
|
43
39
|
},
|
|
44
40
|
"^" => {
|
|
@@ -49,10 +45,10 @@ class Code
|
|
|
49
45
|
"bitwise_xor" => {
|
|
50
46
|
name: "bitwise_xor",
|
|
51
47
|
description: "returns true when exactly one boolean is true.",
|
|
52
|
-
examples: [
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
examples: %w[
|
|
49
|
+
true.bitwise_xor(false)
|
|
50
|
+
true.bitwise_xor(true)
|
|
51
|
+
false.bitwise_xor(false)
|
|
56
52
|
]
|
|
57
53
|
}
|
|
58
54
|
}.freeze
|