Class: Cambridge::Tokens::Command

Inherits:
Base
  • Object
show all
Defined in:
lib/cambridge/tokens/command.rb

Instance Method Summary collapse

Methods inherited from Base

#de_codepoint

Constructor Details

#initialize(name) ⇒ Command

Returns a new instance of Command.



4
5
6
# File 'lib/cambridge/tokens/command.rb', line 4

def initialize(name)
  @name = de_codepoint name
end

Instance Method Details

#to_rubyObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cambridge/tokens/command.rb', line 8

def to_ruby
  case @name
  when 'dump'
    "puts @stack.inspect"
  when 'prints'
    "puts @stack.pop"
  when 'printi'
    "puts @stack.pop.to_s"
  when 'add'
    "@stack.push(@stack.pop + @stack.pop)"
  when 'mult'
    "@stack.push(@stack.pop * @stack.pop)"
  end
end