2010/6/9 lalawawa <usenet / ccjj.info>:
> In perl, one is able to sort of 'declare' variables by mentioning them
> in 'my' statements.      
> weren't previously thus 'declared' are allowed.     
> it catches typos that might be difficult to detect in testing.
>
> Does ruby have an equivalent mechanism?

Better: you do not need an additional declaration, rather Ruby will
catch situations for you where you forgot to initialize (aka assign) a
local variable:

$ ruby19 -e 'puts foo'
-e:1:in `<main>': undefined local variable or method `foo' for
main:Object (NameError)

The grain of salt is this

- this does not work for instance variables, these spring into
existence whenever you use them,

- because there is the method local variable ambiguity you might still
run into erroneous situations when forgetting to initialize a local
variable which shares name with a method.

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/