E
EdUarDo
Hi all, I have this class:
class Tactic
attr_reader :name, :cells
class Cell
attr_reader :x, :y, osition, layerId
attr_writer :x, :y, osition, layerId
def initialize(x, y, position)
@x = x
@y = y
@playerId = 0
@position = position
end
def to_s
puts "(#@x, #@y): #@position, #@playerId"
end
end
def loadDefaultTactic
file = File.new('tactics.dat')
# Identificador de la tactica
@name = file.readline
# Posiciones
file.each(';') {
|line| coords = line.split(',')
x, y = coords[0].to_i, coords[1].to_i
@cells << Cell.new(x, y, getPosition(x, y))
}
file.close
end
def initialize
@cells = Array.new
# TODO Hay que leer el fichero de datos y cargar la tactica por defecto
end
def to_s
puts "#@name"
end
end
I do:
tactic = Tactic.new
tactic.loadDefaultTactic
puts tactic
and get:
4-4-2
#<Tactic:0xb78db8fc>
Why do I get the internal representation of Tactic?
Why is not the response '4-4-2' only?
4-4-2
class Tactic
attr_reader :name, :cells
class Cell
attr_reader :x, :y, osition, layerId
attr_writer :x, :y, osition, layerId
def initialize(x, y, position)
@x = x
@y = y
@playerId = 0
@position = position
end
def to_s
puts "(#@x, #@y): #@position, #@playerId"
end
end
def loadDefaultTactic
file = File.new('tactics.dat')
# Identificador de la tactica
@name = file.readline
# Posiciones
file.each(';') {
|line| coords = line.split(',')
x, y = coords[0].to_i, coords[1].to_i
@cells << Cell.new(x, y, getPosition(x, y))
}
file.close
end
def initialize
@cells = Array.new
# TODO Hay que leer el fichero de datos y cargar la tactica por defecto
end
def to_s
puts "#@name"
end
end
I do:
tactic = Tactic.new
tactic.loadDefaultTactic
puts tactic
and get:
4-4-2
#<Tactic:0xb78db8fc>
Why do I get the internal representation of Tactic?
Why is not the response '4-4-2' only?
4-4-2