From b18757c14c11ebc8fa61679e0b1eba12d288d1d3 Mon Sep 17 00:00:00 2001 From: David Litvak Bruno Date: Sun, 20 May 2012 01:28:08 -0300 Subject: [PATCH] extraida la clase Termino --- ruby/terminos.rb | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/ruby/terminos.rb b/ruby/terminos.rb index 2912e2b..9ce1409 100644 --- a/ruby/terminos.rb +++ b/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 @@ -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 @@ -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