Hello, I'm starting with the ruby language and I encounter the following problem that is at the time of starting message through to_s:
main class
require File.expand_path("lib/Livro")
biblioteca = []
instancia = Livro.new "Ruby", "X", "Casa do Código", 56.40
instancia_dois = Livro.new "Java", "Y", "Casa do Código", 78.9
biblioteca << instancia
biblioteca << instancia_dois
puts biblioteca
class accessed
class Livro
attr_accessor :preco,:autor,:editora,:nome
def initialize nome_livro, autor,_editora = nil, preco
@nome = nome_livro
@autor = autor
@editora = editora
@preco = preco
end
def to_s
"Autor: #{@nome}, Autor: #{@autor}, Editora: #{@editora},Preço: #{@preco}"
end
end
In the output of the code instead of the message attached to to_s only the addresses of the objects appear, I tried to search the internet but found nothing that could help thanks right away.