How do you evaluate text as code in Ruby? I''m sure there''s a technical term for this... Thanks Chris -- Posted via http://www.ruby-forum.com/.
I''ve just found out, you use "eval", suprisingly enough -- Posted via http://www.ruby-forum.com/.
eval("code") On 8/1/06, Chris <cadams1342@hotmail.com> wrote:> > How do you evaluate text as code in Ruby? > I''m sure there''s a technical term for this... > > Thanks > Chris > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060801/cbd6dda4/attachment.html
dblack@wobblini.net
2006-Aug-01 12:14 UTC
[Rails] How do you evaluate text as code in Ruby?
Hi -- On Tue, 1 Aug 2006, Chris wrote:> How do you evaluate text as code in Ruby? > I''m sure there''s a technical term for this...There are two steps: 1. Use eval(string) 2. Examine your program, find out what led you to use eval, and fix it :-) David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <----- http://dablog.rubypal.com => D[avid ]A[. ]B[lack''s][ Web]log http://www.manning.com/black => book, Ruby for Rails http://www.rubycentral.org => Ruby Central, Inc.
On Aug 1, 2006, at 6:20 AM, Chris wrote:> How do you evaluate text as code in Ruby? > I''m sure there''s a technical term for this... > > Thanks > ChrisBe sure to check out eval''s cousins instance_eval, class_eval and module_eval. Instance eval is particularly cool because it can take a block too, eliminating the ''code in a string'' problem. There''s also implementations of instance_exec which is like instance_eval but with arbitrary argument passing. While you''re into the meta-programming world, define_method, remove_method and alias are pretty darn cool too. It''s a wide wide ruby world :) -Mat