From: windwiny Date: 2013-05-10T15:33:17+09:00 Subject: Re: Hash name is not recognized by Ruby unless first letter is capitalized --e89a8ff1c99c95798504dc575788 Content-Type: text/plain; charset=UTF-8 key "def" define a scope . function pronounce not see outside variable "mc", "Mc" is constance, can used by anywhere. 2013/5/10 Phil Lou > Hi, all: > > My little test code below will not recognize the hash variable > if its first letter is not capitalized. If the first letter is > capitalized, > then everything is OK. I'll appreciate any explanation for this > behavior. > > =========================== > # failure if declared as "mc". Must capitalize "M", lowercase "m" > # such as "mc" will result in compilation errors. > Mc = { "a" => "aay", "b" => "bee", "c" => "cee" } > > def pronounce (aStr) > array_of_chars = aStr.split(""); > array_of_chars.map { |eachChar| Mc[eachChar] }; > end > > puts "#{pronounce("abc")}"; > ============================ > > Thanks, > > PL > > -- > Posted via http://www.ruby-forum.com/. > > --e89a8ff1c99c95798504dc575788 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
key "def" define a scope .

function pronounce not see outside variable "mc",=C2=A0
=
"Mc" is constance, can used by anywhere.



2= 013/5/10 Phil Lou <lists@ruby-forum.com>
Hi, all:

My little test code below will not recognize the hash variable
if its first letter is not capitalized. If the first letter is
capitalized,
then everything is OK. I'll appreciate any explanation for this
behavior.

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D
# failure if declared as "mc". Must capitalize "M", low= ercase "m"
# such as "mc" will result in compilation errors.
Mc =3D { "a" =3D> "aay", =C2=A0 "b" =3D>= ; "bee", =C2=A0"c" =3D> "cee" }

def pronounce (aStr)
=C2=A0 array_of_chars =3D aStr.split("");
=C2=A0 array_of_chars.map { |eachChar| Mc[eachChar] };
end

puts "#{pronounce("abc")}";
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D

Thanks,

PL

--
Posted via http://= www.ruby-forum.com/.


--e89a8ff1c99c95798504dc575788--