From: Chad Perrin Date: 2007-09-17T03:22:52+09:00 Subject: Re: Newbie help On Sun, Sep 16, 2007 at 11:27:35AM +0900, John Joyce wrote: > On Sep 15, 2007, at 8:10 PM, Jeremy Woertink wrote: > >> > >Welcome to ruby. First to start the question about Symbols. Well, they > >are used in hashes a lot, you could very well do { 'shape' => 'sock' } > >and it works the same, but just to be consistent you use the object > >as a > >symbol and it's value as what ever else. There is a lot more to that, > >and i'm sure someone else will reply to tell you that. As I understand it, there's generally less processing time involved in resolving symbols than strings, but if you have a very long-running program that performs some very similar actions involving symbols over and over again you might end up consuming a lot of RAM because symbols never really go away throughout the run of the program. There may be a way to get the interpreter to clear the hash table that stores symbols, but I don't really know what it is off the top of my head. If there's such a thing, it probably involves scoping rules in Ruby, and maybe a little luck. > > To give further detail a block has two possible delimiter pairs { } > or do end > As far as the interpreter is concerned they're same. Again, if I recall correctly, that's not strictly true -- but the only difference as far as I'm aware is precedence. I seem to recall that braces have a higher precedence than do...end. This should only really come into play when you are doing some fancy stuff on the line where the do or open-brace appears, before the beginning of the block, I think. Keep in mind I'm not Matz, Why, or the Pragmatic Programmer guys. I'm not what I'd call a Ruby "expert". I may have inadvertently misrepresented some feature of the language. Despite a growing preference for Ruby in most cases, I still have more experience with Perl, and know that language better. Take what I say with a grain of "maybe he doesn't know what he's talking about" when I start talking about the quirks and gotchas of working with Ruby. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] McCloctnick the Lucid: "The first rule of magic is simple. Don't waste your time waving your hands and hopping when a rock or a club will do."