Fri, 20 Apr 2007
Ruby has variable scoping
Gareth joined me in the d'oh! club today when I revealed to him the revelation that Ryan provided me back in January. Ruby has variable scoping, meaning that this code works just fine:
a = 1
puts a # nil
Up until Ryan revealed this to me, I had been merrily (and needlessly) declaring my variables outside the control structures that defined them. Maybe Gareth and I are the only ones who weren't aware of this aspect of Ruby (and many other dynamic languages), but just in case, I thought I'd share it with you.