symbols vs. strings

M

Mark Volkmann

I got the impression that when a method expects a Hash containing
certain keys, I can generally specify the keys using either Symbol or
String objects. So I tried this.

h =3D {}
h[:foo] =3D 19
h['foo'] =3D 20

and was surprised to see that those are treated as distinct entries in the =
Hash.

So how is it that I can sometimes choose whether I want to specify a
given key as either a Symbol or a String?

For example, when using Tk and w represents some widget, I think I can
say either

w.pack:)side =3D> 'top')

or

w.pack('side' =3D> 'top')

--=20
R. Mark Volkmann
Partner, Object Computing, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top