[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

String.intern vs String.to_sym

Ian Hunter

7/28/2008 9:07:00 PM

Can anyone make a case for ever using String.intern? It seems to be
nothing more than an alias to to_sym on String, and since it's not
defined on Symbol, you can't ducktype a var to get a symbol.

I'm trying to understand why this even exists in the Ruby language, it
doesn't seem like it would be useful for anything. variable.to_sym
seems to be the safer route to always use.

Thanks, ian
--
Posted via http://www.ruby-....

2 Answers

Eric Hodel

7/28/2008 9:29:00 PM

0

On Jul 28, 2008, at 14:07 PM, Ian Hunter wrote:
> Can anyone make a case for ever using String.intern? It seems to be
> nothing more than an alias to to_sym on String, and since it's not
> defined on Symbol, you can't ducktype a var to get a symbol.

#intern came first, #to_sym is an alias of #intern.

> I'm trying to understand why this even exists in the Ruby language, it
> doesn't seem like it would be useful for anything. variable.to_sym
> seems to be the safer route to always use.

It's useful for backwards compatibility.

Stephen Celis

7/28/2008 10:23:00 PM

0

On Jul 28, 2008, at 14:07 PM, Ian Hunter wrote:

> [intern]'s not defined on Symbol

It's worth noting that Symbol#intern is defined in 1.9.0.

Stephen