From: Florian Gross Date: 2003-10-16T08:00:04+09:00 Subject: Re: General Ruby Programming questions Simon Kitching wrote: > Hi, Moin! > I have a string containing the name of a class, and want to get the > corresponding Class object. My current approach is: > Module.class_eval(classname) > Is this the best approach? It isn't -- an user might inject arbitary code. Use this instead: irb(main):001:0> Object.const_get('Class') => Class > (b) changing "require" searchpath > The $: variable holds the path used to locate files when the "require" > command is used. However this variable is read-only. In Perl, it is > possible to modify the equivalent path; can this be done in ruby? It might be read-only, but that doesn't mean that you can't change the object which it refers to: irb(main):002:0> $:.push('new') => [..., 'new'] > (c) how invoke "hidden" methods? Simply send the message a method invocation would produce yourself: irb(main):003:0> 5.send(:rand) => 0.748920713318512 > (d) iterating in reverse > I have an Array object, and wish to iterate over its members in reverse. > I would prefer not to have to create a new Array object in order to do > this iteration. Is there any way other than writing irb(main):004:0> [1, 2, 3].reverse_each { |item| puts item } 3 2 1 Regards, Florian Gro�