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

403
Vistas
Ruby Method definition Syntax with & keyword
class ExchangeUtil
  def exchange_to(other_currency, date = Date.current, &)
      @bank.exchange_with_on(self, other_currency, date, &)
  end
end

What is the siginificance of & in method definition and method calls?

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

0

It's a new feature in Ruby 3.1: Anonymous block argument

It's just a shortcut for when you have a block argument for a function whose only purpose is to be passed to another function. Older syntax for that would've been

class ExchangeUtil
  def exchange_to(other_currency, date = Date.current, &block)
      @bank.exchange_with_on(self, other_currency, date, &block)
  end
end

The param &block could've had any name, like &my_block, but the name was generally meaningless, so they made it "anonymous".

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