Class: Tataru::Instruction

Inherits:
Object
  • Object
show all
Defined in:
lib/tataru/instruction.rb

Overview

a thing to do

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.expected_paramsObject

Returns the value of attribute expected_params.



7
8
9
# File 'lib/tataru/instruction.rb', line 7

def expected_params
  @expected_params
end

Instance Attribute Details

#memoryObject

Returns the value of attribute memory.



21
22
23
# File 'lib/tataru/instruction.rb', line 21

def memory
  @memory
end

Class Method Details

.expects(symbol) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/tataru/instruction.rb', line 9

def expects(symbol)
  @expected_params ||= []
  @expected_params << symbol

  define_method symbol do
    return nil if @memory&.hash.nil?

    memory.hash[:temp][symbol]
  end
end

Instance Method Details

#execute(memory) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/tataru/instruction.rb', line 23

def execute(memory)
  @memory = memory
  self.class.expected_params&.each do |symbol|
    unless memory.hash[:temp].key? symbol
      raise "required param #{symbol} not found"
    end
  end

  run
end

#runObject



34
# File 'lib/tataru/instruction.rb', line 34

def run; end