Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
Does Atom break ruby to_s override?

I want puts to return @value. The code is below:

class Tile
  def initialize(value, given=false)
    @value = value
    @given = given
  end

  def newValue(value)
    @value = value if @given == false
  end

  def to_s
    @value
  end

end

t = Tile.new(5)
t.newValue(6)
debugger
puts t

This results in the printing of just the object id, no variables.

Why? And what is going wrong here? Is it an Atom thing?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

puts prints each argument by calling its to_s method. It also expects the to_s method to return a string. If to_s returns something else it ignores that value and prints the object's class and id instead.

In your example, @value is an integer. To fix your code:

def to_s
  @value.to_s
end
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda