From: thunk Date: 2010-04-01T01:20:08+09:00 Subject: Re: return number of spaces at the beginning of a line On Mar 31, 7:19 am, Aldric Giacomoni wrote: > 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 viahttp://www.ruby-forum.com/. just quickly: they start life as a method name so i was hoping they could stay symbols - but i need a tie breaker for the one level key that becomes a simpleton method (name) in this "whiteboard" class. i keep trying to use all symbols. note: ruby is not fighting me with the /?!/ - so the door seems open to bite the bullet and convert -> append -> reconvert but it "hurts" my sense of symmetry - but thanks - that makes perfect sense (and now that i think about it- it had to be that way, almost). thunk