From: dblack@... Date: 2006-07-29T10:29:09+09:00 Subject: Re: does ":" have an anolog in another language? Hi -- On Sat, 29 Jul 2006, Ike wrote: > > "Tim Hunter" wrote in message > news:eado93$s4a$1@foggy.unx.sas.com... >> Ike wrote: >>> does the colon operator have an anolog in say, Java or C++ ? It seems to >>> be a reference pointer. Am i mistaken in assuming this? Thanks, Ike >> Tokens that start with colon are called "symbols". >> >> Check out the Symbol class at ruby-doc: http://www.ruby-doc.org/core/ > > Ok....so why not just use a String then, and test for equality of the values > of the String? I mean, if this is something which has no anolog, say, in > Java, or c++ (although these do seem like refrence pointers to me, ie. > pointers whose l-lvalue we cannot acces) then why use them? -Ike Well... if they're not useful, then I don't think it matters whether or not they have an analog in Java or C++ -- and, come to think of it, the same thing is true if they *are* useful :-) Ruby exposes symbols for our use, as I understand it, in large part because they are processed faster internally than strings, and less consumptive of memory than strings. If you use a symbol twice: hash[:a] = 1 puts hash[:a] you're using the same symbol object twice. If you do the same with a string: hash["a"] = 1 puts hash["a"] you're creating two strings objects. People also like symbol literals in some contexts, especially as hash keys, because of how they look. (I have no strong feelings about that one way or the other.) David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <----- http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log http://www.manning.com/black => book, Ruby for Rails http://www.rubycentral.org => Ruby Central, Inc.