From: Aldric Giacomoni Date: 2010-03-31T21:19:12+09:00 Subject: Re: return number of spaces at the beginning of a line thunk wrote: > Adding a '+' method to Kernel for symbols would reduce code clutter > but still ultimately end up requiring conversion from symbols to > strings to do > the append operation, right? > > (ruby 1.9 is allowing me to do more with the ?! chars than I think I > remember 1.8 where I think I remember getting some errors around > this. ) > > I would not normally care much, or feel a particular need to > understand what is going on under the hood, but I have a performance > issue right here and this happens be one of the things I'm working on. > > comments? > > then, what would be the best form to add two symbols together (ending > up with a symbol again) > You're thinking about it the wrong way. A symbol is a pointer to a specific address in memory, kinda like a variable. Do you expect this code to work? a = 5 b = NeuralNetwork.new puts (a + b).to_s ... You'll get an error, because a and b are just pointers to the objects. Symbols are a bit different; while they are "faster" than plain variables, or than strings, they never get garbage collected (I can not explain any more than this, but many around here know Ruby's deep magic well), and they always refer to the same memory space. I think you're using symbols inappropriately. What -are- you doing with them? If you need to add two names together, then my guess is, just stick with strings. -- Posted via http://www.ruby-forum.com/.