For Programmers: Free Programming Magazines  


Home > Archive > Ruby > August 2005 > Re: symbols vs. strings









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: symbols vs. strings
Mark Volkmann

2005-08-28, 6:59 pm

On 8/26/05, Brian Schr=F6der <ruby.brian@gmail.com> wrote:
> On 26/08/05, Mark Volkmann <r.mark.volkmann@gmail.com> wrote:
the Hash.[color=darkred]
=20[color=darkred]
> That can e.g. be implemented like this:
>=20
> def pack(arghash)
> arghash =3D arghash.inject({}) { | r, (k, v) | r[k.to_s] =3D v; r }
> side =3D arghash['side']
> ...
> end


Just to clarify, are you saying that ...

1) If I want my code that accepts a Hash parameter to allow keys to be
either Symbols or Strings, I need to use an approach like you showed
above.

2) Many existing Ruby classes do this.

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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com