Created
October 12, 2009 19:55
-
-
Save EmmanuelOga/208684 to your computer and use it in GitHub Desktop.
Programator2000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'singleton' | |
set_trace_func proc { |event, file, line, id, binding, classname| | |
if event == "line" && file == "Programator2000" | |
puts Programator2000.instance.to_lines[line - 1] | |
print "[NEXT]" | |
gets | |
end | |
} | |
class Programator2000 < Struct.new(:code) | |
include Singleton | |
def to_lines | |
code.split("\n") | |
end | |
def to_ruby | |
code.gsub(/mientras/, "while").gsub(/imprimir/, "puts") | |
end | |
def run! | |
eval(to_ruby, binding, "Programator2000") | |
end | |
end | |
Programator2000.instance.code = <<-CODE | |
a = 1 | |
mientras a < 5 | |
imprimir a | |
a = a + 1 | |
end | |
imprimir "Valor final de a: " | |
imprimir a | |
CODE | |
Programator2000.instance.run! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment