Tom M
8/14/2007 8:00:00 PM
On Aug 14, 11:26 am, thomas.mack...@gmail.com wrote:
> I often find myself writing methods with the following form:
>
> def foo(sym_or_str)
> @iv = sym_or_str
> end
>
> when I go to compare later vs @iv, I can do:
>
> def compare_vs_iv(arg)
> if arg.to_s == @iv.to_s then
> ...
> end
> ...
> end
>
> but I can't do:
>
> if arg.intern == @iv.intern then
> ...
> end
>
> This is because symbols don't respond to intern. Is there any good
> reason Symbol doesn't respond to intern, while String responds to
> to_s, Array responds, to to_a, etc.? If not, I would like to propose
> that the intern method be added to Symbol at some point.
>
> Thoughts?
I knew about overloading Symbol, but I think we can all agree that's
not really a practical solution for use in a bigger system. I didn't
know about to_sym though, and I think that's perfect! Shows what I
get for thinking that I knew the core API pretty well...
Thanks... --Tom