Top Level Namespace

Defined Under Namespace

Modules: Zaid

Constant Summary collapse

ARITHMETIC_OPERATIONS =
%i[+ * - /].freeze
COMPARISON_OPERATIONS =
%i[> < >= <= == !=].freeze
Constants =
{}
RootContext =
Zaid::Runtime::Context.new(root_self)

Instance Method Summary collapse

Instance Method Details

#define_arithmetic_operations(class_name, operations) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/zaid/runtime/bootstrap.rb', line 9

def define_arithmetic_operations(class_name, operations)
  operations.each do |operation|
    Constants[class_name].def operation do |receiver, arguments|
      perform_arithmetic_operation(receiver, arguments, operation, class_name)
    end
  end
end

#define_comparison_operations(class_name, operations) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/zaid/runtime/bootstrap.rb', line 17

def define_comparison_operations(class_name, operations)
  operations.each do |operation|
    Constants[class_name].def operation do |receiver, arguments|
      result = receiver.ruby_value.send(operation, arguments.first.ruby_value)

      result ? Constants['صحيح'] : Constants['خاطئ']
    end
  end
end

#perform_arithmetic_operation(receiver, arguments, operation, class_name) ⇒ Object



27
28
29
30
31
# File 'lib/zaid/runtime/bootstrap.rb', line 27

def perform_arithmetic_operation(receiver, arguments, operation, class_name)
  result = receiver.ruby_value.send(operation, arguments.first.ruby_value)

  Constants[class_name].new_with_value(result)
end