Class: Cambridge::Tokens::Command
- Defined in:
- lib/cambridge/tokens/command.rb
Instance Method Summary collapse
-
#initialize(name) ⇒ Command
constructor
A new instance of Command.
- #to_ruby ⇒ Object
Methods inherited from Base
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_ruby ⇒ Object
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 |