M
Marc Heiler
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
The problem is that I usually work with strings. In fact, to simplify my
life, I begin to believe it would be easier for me to throw symbols away
entirely whenever I have a case/when structure. (I rarely use symbols at
all anyway.)
Looking at other people's ruby code they rarely seem to use neither
strings nor symbols - most of the time they appear to use 'when
/some_regex/' or 'when Array'.
Or something peculiar like:
case value
when ::Hash
Which I am not even sure what it does...
Noone seems to use :symbols at all inside there, so it seems that it
would be simpler to not use symbols inside case/when structures as well.
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
The problem is that I usually work with strings. In fact, to simplify my
life, I begin to believe it would be easier for me to throw symbols away
entirely whenever I have a case/when structure. (I rarely use symbols at
all anyway.)
Looking at other people's ruby code they rarely seem to use neither
strings nor symbols - most of the time they appear to use 'when
/some_regex/' or 'when Array'.
Or something peculiar like:
case value
when ::Hash
Which I am not even sure what it does...
Noone seems to use :symbols at all inside there, so it seems that it
would be simpler to not use symbols inside case/when structures as well.