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

315
Vistas
Ruby: How to reference a variable defined outside of a module

How do I pass processor_pool to the method inside the module?

class Dummy

  def initialize
    processor_pool = Concurrent::FixedThreadPool.new(10)

    @threadpool = Module.new do
      extend Concurrent::Promises::FactoryMethods
      def self.default_executor
        return processor_pool  # this cannot find the processor_pool variable
      end
    end
  end

end

I get the same error even if I make it an instance variable like @processor_pool

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

0

Something like this (I simplified your class a bit to get rid of dependencies for the sake of example, but its structure is the same):

class Dummy
  attr_reader :threadpool
  
  def initialize
    processor_pool = "It works"

    @threadpool = Module.new do
      define_method :default_executor do
        return processor_pool  # this cannot find the processor_pool variable
      end
      module_function :default_executor
    end
  end
end

Dummy.new.threadpool.default_executor # => "It works"
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