From: Yossef Mendelssohn Date: 2009-03-05T01:44:39+09:00 Subject: Re: Any solutions to Ruby's inconsistencies? On Mar 4, 10:02 am, "C. Dagnon" wrote: > 3. Originally I was taught that symbols were the salvation of memory and > key problems - and they certainly sounded like it.  Up until the point a > few days later when one (Rails?) map used Symbols and another used > Strings.  Ouch. >     Without any explicit typing abilities in the language (optional or > otherwise?) it seems like the only solution is to return to basic string > matches: >     regex = Regexp.compile("^#{matcher.to_s}$", Regexp::IGNORECASE) >     key = map.keys.find{ |key| key.to_s =~ regex } > Yuck. There's been endless discussion and confusion about Symbols, Strings, what they mean, what they should be used for, and their relation to each other. Rails did not help with HashWithIndifferentAccess, though I imagine they thought they would. But I don't want to start anything like that up. I just want to point out that a lot of that code is unnecessary and could just be: key = map.keys.detect { |k| k.to_s.downcase == matcher.to_s.downcase } Specifically, "#{something.to_s}" is not required because string interpolation calls to_s on the object. And anyway, this example seems confused with Symbol vs. String as well as case-insensitive matching. If you want something like that, you write your own Hash (or Map) subclass or find something someone else wrote. Maybe there's HashWithReallyIndifferentAccess or HashThatJustKnowsWhatYouMean or HashThatWillGiveYouTheValueOfSomeTangentionallyRelatedKey. > 4. And what's up with Ruby incorrectly naming their Map 'Hash'? This isn't only a Ruby thing. I'm used to it, but then again I came to Ruby from Perl. At least they're not called "dictionaries", right? Am I right? > Or is my C.S. idea of a Hash too limited?  Granted in Java they > have HashMap, but if you enter one value and get a second one > out it is a Map, regardless of how the keys are stored. Hey, why aren't Arrays called Maps instead? -- -yossef