From: Robert Klemme Date: 2009-03-14T02:27:53+09:00 Subject: Re: case when - symbols or strings? On 13.03.2009 13:51, Gary Wright wrote: > On Mar 13, 2009, at 8:06 AM, Marc Heiler wrote: > >> Picture a small method which accepts one argument. Inside this >> method is >> simply a case/when menu, nothing else. The question I now have >> is ... - >> should the argument be coerced to string or symbol? >> case argument.to_sym >> vs >> case argument.to_s OP: The question is, where does "argument" come from and what do you want to do with this? > Hard to generalize but if you coerce to a string > you'll create a string that can be garbage collected. > If you coerce to symbol you create a new symbol that > can't be garbage collected. > > If your argument is coming from some external source > (e.g. an HTML form) and isn't constrained in any way, > then coercing to a symbol will introduce a small > 'memory leak' in your program every time the case > statement is executed. Not necessarily: it depends on the input. Kind regards robert -- remember.guy do |as, often| as.you_can - without end