Skip to content

Commit

Permalink
extraida la clase Termino
Browse files Browse the repository at this point in the history
  • Loading branch information
dlitvakb committed May 20, 2012
1 parent 0f4d2ff commit b18757c
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions ruby/terminos.rb
@@ -1,25 +1,23 @@
class TerminoBooleano
def initialize termino
posibles = {"true" => true, "false" => false}
@termino = posibles[termino]
end

class Termino
def eval
@termino
end
end

class TerminoNumerico
class TerminoBooleano < Termino
def initialize termino
@termino = termino.to_i
posibles = {"true" => true, "false" => false}
@termino = posibles[termino]
end
end

def eval
@termino
class TerminoNumerico < Termino
def initialize termino
@termino = termino.to_i
end
end

class TerminoIf
class TerminoIf < Termino
def initialize termino_if
@if_offset = 'if ('.size
@then_offset = ') then ('.size
Expand All @@ -30,9 +28,9 @@ def initialize termino_if

@condicion_text = termino_if.slice(@if_offset..posicion_then - 2)
if (Programa.new @condicion_text).eval
@resultado = (Programa.new termino_if.slice((posicion_then + @then_offset - 1)..(posicion_else - 1))).eval
@termino = (Programa.new termino_if.slice((posicion_then + @then_offset - 1)..(posicion_else - 1))).eval
else
@resultado = (Programa.new termino_if.slice(posicion_else + @else_offset..-2)).eval
@termino = (Programa.new termino_if.slice(posicion_else + @else_offset..-2)).eval
end
end

Expand Down Expand Up @@ -64,8 +62,8 @@ def _encontrar_else seccion
end

def eval
puts "#{@current_step} -> Condicion: #{(Programa.new @condicion_text).eval}"
@resultado
puts " -> Condicion: #{(Programa.new @condicion_text).eval}"
super
end
end

Expand Down

0 comments on commit b18757c

Please sign in to comment.