Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
Variable scope within a block in ruby

I'm struggling with variable scope within a block in ruby. I learnt that do..end that follows while, until, or for loops are not blocks because while, until, or for are not method calls. So they don't create their own inner scope. but this example confused me

loop do
  b = 2
  p b # => 2
  break
end
p b

Here in this example b is initialized with the number 2 inside the do..end. The puts method is called with the variable b passed to it as an argument, and it through an NameError. saying that b is undefined local variable, but as i said before the do..end that follows while, until, or for loops don't create their own inner scope

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

but as i said before the do..end that follows while, until, or for loops don't create their own inner scope

Exactly. But there is no while, until, or for loop in your code.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda