Class: Code::Object::Code
Constant Summary
collapse
- CLASS_DOCUMENTATION =
{
name: "Code",
description: "stores parsed source code for later evaluation.",
examples: [
"Code",
"Code.evaluate(\"1 + 2\")",
"Code.new(\"1 + 2\").evaluate"
]
}.freeze
- CLASS_FUNCTIONS =
{
"evaluate" => {
name: "evaluate",
description: "evaluates source code and returns the result.",
examples: [
"Code.evaluate(\"1\")",
"Code.evaluate(\"1 + 2\")",
"Code.evaluate(\"[1, 2].size\")"
]
}
}.freeze
- INSTANCE_FUNCTIONS =
{
"evaluate" => {
name: "evaluate",
description: "evaluates stored source code and returns the result.",
examples: [
"Code(\"1\").evaluate",
"Code(\"1 + 2\").evaluate",
"Code(\"[1, 2].size\").evaluate"
]
}
}.freeze
Constants inherited
from Code::Object
NUMBER_CLASSES
Concerns::Shared::COMPOUND_ASSIGNMENT_OPERATORS, Concerns::Shared::OPERATOR_METHOD_ALIASES, Concerns::Shared::SHARED_OPERATORS
Instance Attribute Summary
#functions, #raw
Class Method Summary
collapse
Instance Method Summary
collapse
class_documentation, class_functions, code_new, #code_new, documentation, documentation_for, documented_functions_for, function_documentation_for, function_documentation_registry_for, functions, inherited_function_documentation_for, instance_functions, maybe, #name, repeat, sorted_dictionary, |
#<=>, #==, #as_json, #blank?, #code_and, #code_as_json, #code_blank?, #code_class_functions, #code_compare, #code_different, #code_documentable_functions, #code_documentation, #code_duplicate, #code_dynamic_call, #code_equal, #code_exclamation_mark, #code_exclusive_range, #code_false?, #code_falsy?, code_fetch, #code_fetch, #code_functions, code_get, #code_get, #code_greater, #code_greater_or_equal, #code_has_key?, #code_inclusive_range, #code_inspect, #code_instance_functions, #code_instance_of?, #code_is_a?, #code_itself, #code_less, #code_less_or_equal, #code_name, #code_nothing?, #code_or, #code_presence, #code_presence_in, #code_present?, #code_respond_to?, #code_same_object?, #code_self, #code_send, code_set, #code_set, #code_something?, #code_strict_different, #code_strict_equal, #code_tap, #code_then, #code_to_boolean, #code_to_class, #code_to_date, #code_to_decimal, #code_to_dictionary, #code_to_duration, #code_to_integer, #code_to_json, #code_to_list, #code_to_nothing, #code_to_parameter, #code_to_range, #code_to_string, #code_to_time, #code_true?, #code_truthy?, #eql?, #falsy?, #hash, #inspect, #multi_fetch, #nothing?, #present?, #sig, #something?, #succ, #to_code, #to_i, #to_json, #to_s, #truthy?
Constructor Details
#initialize(*args, **_kargs, &_block) ⇒ Code
Returns a new instance of Code.
45
46
47
48
|
# File 'lib/code/object/code.rb', line 45
def initialize(*args, **_kargs, &_block)
self.raw =
(args.first.is_a?(Node::Code) ? args.first : Node::Code.new(::Code.parse(args.first.to_s)))
end
|
Class Method Details
.call(**args) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/code/object/code.rb', line 56
def self.call(**args)
code_operator = args.fetch(:operator, nil).to_code
globals = multi_fetch(args, *GLOBALS)
case code_operator.to_s
when "evaluate"
sig(args) { Object }
code_evaluate(*args.fetch(:arguments, []).to_code.raw, **globals)
else
super
end
end
|
.code_evaluate(*args, **globals) ⇒ Object
50
51
52
53
54
|
# File 'lib/code/object/code.rb', line 50
def self.code_evaluate(*args, **globals)
code_args = args.to_code
new(*code_args.raw).code_evaluate(**globals)
end
|
.function_documentation(scope) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/code/object/code.rb', line 38
def self.function_documentation(scope)
return INSTANCE_FUNCTIONS if scope == :instance
return CLASS_FUNCTIONS if scope == :class
{}
end
|
Instance Method Details
#call(**args) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/code/object/code.rb', line 69
def call(**args)
code_operator = args.fetch(:operator, nil).to_code
globals = multi_fetch(args, *GLOBALS)
case code_operator.to_s
when "evaluate"
sig(args)
code_evaluate(**globals)
else
super
end
end
|
#code_deep_duplicate ⇒ Object
86
87
88
|
# File 'lib/code/object/code.rb', line 86
def code_deep_duplicate
self.class.new(raw)
end
|
#code_evaluate(**globals) ⇒ Object
82
83
84
|
# File 'lib/code/object/code.rb', line 82
def code_evaluate(**globals)
raw.evaluate(**globals)
end
|