On Jan 1, 7:24=A0pm, RichardOnRails
<RichardDummyMailbox58... / USComputerGurus.com> wrote:
> The following program:
>
> # K:\Analysis
> # TestUndefinedLocalVar_hash.rb
>
> a =3D []
> a << "xyz"
> a << hash
> a << undefined
>
> crashes on line 8 (a << undefined) rather than on line 7 (which
> apparently appends a reference to the undefined "hash" to the array.
> What causes this mythical creation of "hash"? =A0Is this behavior
> defined anywhere?
>
> If it matters, =A0the following explains how I encountered this problem:
>
> I have a program which had been using a local var named "hash". =A0Use
> of that name caused no problem.
> However, I decided I should change the value assigned to hash, =A0so I
> changed all references to it to "hash_string" ... all but one. =A0I
> expected that after I made changes to the way hash_string was
> computed, =A0my program would fail when the reference to the now-
> undefined hash was encountered. =A0No such luck.
>
> Thanks in Advance,
> Richard

> HTH
That certainly helps in that it shows me what Ruby was "thinking".

RubyDocs shows that lots of class have hash methods (maybe because
they all inherit from Object.)  I listed a few "uses" below but have
adopted a new programming rule:  don't use Ruby method-names as local
variables.

Below are the few examples that seem pretty useless to me.

Best wishes,
Richard

a =3D []
# a =3D "" # Can't append hash to a string
a << hash
a << "xyz"