tag:blogger.com,1999:blog-12467669.post7443031011897262149..comments2023-04-29T07:23:25.825-04:00Comments on Jay Fields' Thoughts: Ruby Evaluation options article on InfoQJayhttp://www.blogger.com/profile/14491442812573747680noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-12467669.post-92077009608225758882007-03-11T14:40:00.000-04:002007-03-11T14:40:00.000-04:00Thanks, Jay! The example helped.Basically, in the ...Thanks, Jay! The example helped.<BR/><BR/>Basically, in the unoptimized case, the eval statement became part of the method you were defining and hence got executed each time the defined method was called; whereas in the optimized case, the eval statement was not part of the defined method itself (as it wasn't within it): the contents of the method were fixed when the method itself was defined using eval. :-) I should have caught that.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-62224533270841355952007-03-11T09:23:00.000-04:002007-03-11T09:23:00.000-04:00AmanI created an example, but it's a bit long and ...Aman<BR/><BR/>I created an example, but it's a bit long and looks much better on pastie.<BR/><BR/>http://pastie.caboo.se/46177<BR/><BR/>If you copy that example and execute it, you'll notice that the call to attr_init_optimized causes an eval to occur; however, all the calls to baz do not require an eval. Conversely, the call to attr_init does not require an eval, but each call to bar causes an eval to occur.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-69258630501993915792007-03-11T07:10:00.000-04:002007-03-11T07:10:00.000-04:00That was a very interesting read. Thanks for the l...That was a very interesting read. Thanks for the link.<BR/><BR/>Umm... could you please (re)explain why your second form of attr_init was better optimized than the first form? <BR/><BR/>I couldn't understand this: "It was not obvious at first to me, but the following solution is far superior since it only requires one call to eval instead of a new eval with each call to the defined method." To me it seems both forms result in the same number of eval calls. What am I not seeing?Anonymousnoreply@blogger.com