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

190
Vistas
When using "and" in ruby, the earth is flat

As I have always been taught in logic, the "and" operator means both values must be true, for the entire statement to be true. If you have many statements chained with "and", then any one of them being false should make the whole claim false. In Ruby, however, I ran into this scenario:

horizon_flat = true
one_up_and_down = true
magellan_fell = false
flat_earth_thesis = horizon_flat and one_up_and_down and magellan_fell

puts("Hey ruby, doesn't the horizon look flat?")
puts(horizon_flat) # true

puts("Isn't there only one up and one down?")
puts(one_up_and_down) # true

puts("Did Magellan fall off the earth?")
puts(magellan_fell) # false

puts("Is the earth flat?")
puts(flat_earth_thesis) # true

Strangely, if I just run the statement itself, it returns false correctly puts(horizon_flat and one_up_and_down and magellan_fell) # false

But if I store that statement in a variable, and later call it, the variable outputs true. Why does ruby think the earth is flat?

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

0

While you expect this:

flat_earth_thesis = horizon_flat and one_up_and_down and magellan_fell

To be evaluated as:

flat_earth_thesis = (horizon_flat and one_up_and_down and magellan_fell)

It is instead evaluated as:

(flat_earth_thesis = horizon_flat) and one_up_and_down and magellan_fell

As noted in comments, review operator precedence.

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