Guest User

Untitled

a guest
Dec 15th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. class Jugador
  2.  
  3. attr_accessor :encarcelado
  4. attr_reader :nombre
  5. attr_reader :saldo
  6. attr_accessor :carta_libertad
  7. attr_accessor :casilla_actual
  8. attr_reader :propiedades
  9.  
  10. # Constructor.
  11. def initialize (nombre = "")
  12. @nombre = nombre
  13. @encarcelado = false
  14. @saldo = 7500
  15. @propiedades = Array.new
  16. @carta_libertad = nil
  17. @casilla_actual = nil
  18. end
  19.  
  20. # Constructor con parámetro
  21. def self.nuevo (nombre)
  22. self.new(nombre)
  23. end
  24.  
  25. # Constructor de copia
  26. def self.copia (otro_jugador)
  27. @nombre = otro_jugador.nombre
  28. @encarcelado = otro_jugador.encarcelado
  29. @saldo = otro_jugador.saldo
  30. @propiedades = otro_jugador.propiedades
  31. @carta_libertad = otro_jugador.carta_libertad
  32. @casilla_actual = otro_jugador.casilla_actual
  33. self
  34. end
  35.  
  36. # ...
  37. end
  38.  
  39. jugador = Jugador.nuevo ("Juan")
  40. puts jugador.nombre
  41. jugador_2 = Jugador.copia(jugador)
  42. puts jugador_2.nombre
  43.  
  44. Juan
  45. NoMethodError: undefined method `nombre' for ModeloQytetet::Jugador:Class
Add Comment
Please, Sign In to add comment