From: craig duncan Date: 2000-12-27T23:03:42+09:00 Subject: [ruby-talk:8111] Re: Hash access method Clemens Hintze wrote: > > You wrote: > > On 23 Dec 2000 12:35:07 +0100, Clemens Hintze wrote: > > > A Python similar solution would looks like: > > > > > But I would use the #{} construct in strings ... > > > > > for letter in 'a' .. 'z' > > > eval "%{letter} = Planet.new" > > > eval "%{letter}.name('%{letter}')" > > > end > > > > > Still very close to Python, isn't it? :-) > > > > the rubified version looks cleaner and more readable. i'm a bit > > suprised at how close to python it DOES look. > > But unfortunately it will not work! :-( > > As somebody else already pointed out, the Ruby compiler would not able > to detect that 'a' .. 'z' are variable names. During compilation these > variables didn't exists, but were created during runtime. If > afterwards you try to access them simply by name, ruby has already > decided to see them as parameterless method call instead of variable > query. I've seen this sort of reference to "compilation" many times in various posts. I think it's probably necessary, to have a good understanding of how Ruby works, to know how it parses things, e.g. does it go completely through the source file first just building parse trees and then execute, does it parse and run as it goes, etc. Unfortunately, references to "compilation" are not helpful (to me) in explaining any of this as it's just not correct. I'd like to see explanations phrased in terms that reveal the true workings of the interpreter more accurately. Just my .02 worth. craig