Class: Code::Object::Global
- Inherits:
-
Code::Object
- Object
- Code::Object
- Code::Object::Global
- Defined in:
- lib/code/object/global.rb
Constant Summary
Constants inherited from Code::Object
Instance Attribute Summary
Attributes inherited from Code::Object
Instance Method Summary collapse
Methods inherited from Code::Object
#<=>, #==, as_json, #as_json, call, #code_and_operator, code_and_operator, code_as_json, #code_as_json, #code_different, code_different, #code_equal_equal, code_equal_equal, code_equal_equal_equal, #code_equal_equal_equal, code_exclamation_point, #code_exclamation_point, code_exclusive_range, #code_exclusive_range, code_inclusive_range, #code_inclusive_range, code_new, code_or_operator, #code_or_operator, #code_self, code_self, #code_to_json, code_to_json, falsy?, #falsy?, #hash, #initialize, inspect, maybe, #multi_fetch, multi_fetch, nothing?, #nothing?, repeat, sig, #sig, #succ, #to_code, to_json, #to_json, to_s, truthy?, #truthy?, |
Constructor Details
This class inherits a constructor from Code::Object
Instance Method Details
#call(**args) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/code/object/global.rb', line 6 def call(**args) code_operator = args.fetch(:operator, nil).to_code code_arguments = args.fetch(:arguments, []).to_code output = args.fetch(:output) code_context = args.fetch(:context).to_code code_value = code_arguments.code_first case code_operator.to_s when "Boolean" sig(args) { Object.repeat } if code_arguments.any? Boolean.new(*code_arguments.raw) else Class.new(Boolean) end when "break" sig(args) { Object.repeat } raise Error::Break, code_value || Nothing.new when "next" sig(args) { Object.repeat } raise Error::Next, code_value || Nothing.new when "Class" sig(args) { Object.repeat } if code_arguments.any? Class.new(*code_arguments.raw) else Class.new(Class) end when "Date" sig(args) { Object.repeat } code_arguments.any? ? Date.new(*code_arguments.raw) : Class.new(Date) when "Decimal" sig(args) { Object.repeat } if code_arguments.any? Decimal.new(*code_arguments.raw) else Class.new(Decimal) end when "Dictionary" sig(args) { Object.repeat } if code_arguments.any? Dictionary.new(*code_arguments.raw) else Class.new(Dictionary) end when "Duration" sig(args) { Object.repeat } if code_arguments.any? Duration.new(*code_arguments.raw) else Class.new(Duration) end when "Function" sig(args) if code_arguments.any? Function.new(*code_arguments.raw) else Class.new(Function) end when "Integer" sig(args) { Object.repeat } if code_arguments.any? Integer.new(*code_arguments.raw) else Class.new(Integer) end when "List" sig(args) { Object.repeat } code_arguments.any? ? List.new(*code_arguments.raw) : Class.new(List) when "Nothing" sig(args) { Object.repeat } if code_arguments.any? Nothing.new(*code_arguments.raw) else Class.new(Nothing) end when "context" sig(args) context when "Object" sig(args) if code_arguments.any? Object.new(*code_arguments.raw) else Class.new(Object) end when "Range" sig(args) { Object.repeat } if code_arguments.any? Range.new(*code_arguments.raw) else Class.new(Range) end when "String" sig(args) { Object.repeat } if code_arguments.any? String.new(*code_arguments.raw) else Class.new(String) end when "Time" sig(args) { Object.repeat } if code_arguments.any? Time.zone.local(*code_arguments.raw) else Class.new(Time) end when "Context" sig(args) { Object.repeat } if code_arguments.any? Context.new(*code_arguments.raw) else Class.new(Context) end when "Code" sig(args) { Object.repeat } code_arguments.any? ? Code.new(*code_arguments.raw) : Class.new(Code) when "Parameter" sig(args) { Object.repeat } if code_arguments.any? Parameter.new(*code_arguments.raw) else Class.new(Parameter) end when "IdentifierList" sig(args) { Object.repeat } if code_arguments.any? IdentifierList.new(*code_arguments.raw) else Class.new(IdentifierList) end when "Html" sig(args) { Object.repeat } code_arguments.any? ? Html.new(*code_arguments.raw) : Class.new(Html) when "Http" sig(args) { Object.repeat } code_arguments.any? ? Http.new(*code_arguments.raw) : Class.new(Http) when "Json" sig(args) { Object.repeat } code_arguments.any? ? Json.new(*code_arguments.raw) : Class.new(Json) when "evaluate" sig(args) { Object } Code.evaluate(code_value.to_s) when "p" sig(args) { Object.repeat } output.puts(*code_arguments.raw.map(&:inspect)) Nothing.new when "print" sig(args) { Object.repeat } output.print(*code_arguments.raw) Nothing.new when "puts" sig(args) { Object.repeat } output.puts(*code_arguments.raw) Nothing.new else code_context = code_context.code_lookup!(code_operator) code_result = code_context.code_fetch(code_operator) if code_result.is_a?(Function) code_result.call(**args, operator: nil) else sig(args) code_result end end end |