~/chapter8ReflectionandMetaprogramming$ cat -n roulette.rb 1 class Roulette 2 def method_missing(name, *args) 3 person = name.to_s.capitalize 4 3.times do 5 number = rand(10) + 1 6 puts "#{number}..." 7 end 8 "#{person} got a #{number}" 9 end 10 end 11 12 number_of = Roulette.new 13 puts number_of.bob 14 puts number_of.frank
El programa contiene un bug. Cuando se ejecuta produce la siguiente salida:
~/chapter8ReflectionandMetaprogramming$ ruby roulette.rb 2> err 1> tutu ~/chapter8ReflectionandMetaprogramming$ cat -n err 1 roulette.rb:6:in `method_missing': stack level too deep (SystemStackError) 2 from roulette.rb:4:in `times' 3 from roulette.rb:4:in `method_missing' 4 from roulette.rb:8:in `method_missing' 5 from roulette.rb:13 ~/chapter8ReflectionandMetaprogramming$ tail tutu 4... 1... 10... 8... 6... 4... 8... 7... 10... 9...¿Sabrias decir cual es el error? ¿Sabrías como arreglarlo?
Casiano Rodriguez León 2015-01-07