From: Phlip Date: 2008-09-09T19:58:40+09:00 Subject: Re: Why is Ruby dynamic? David Masover wrote: > A nitpick, but... string evals considered harmful! >> eval ' > I always loved define_method. I recently tried define_method and it didn't work, so I fell back to eval. (Note to the newbs: Try things the most progressive way possible, such as a fixed version of Dave's version of my example, before trying a hack...) Here's the lines, from inspect_sql: def self._decorate_explainers(explains) #:nodoc: def explains.find_statements(regexp) return AssertEfficientSql._decorate_explainers(select{|explanation| explanation[:statement] =~ regexp }) end (_multiples + _singulars).each do |rollup, explainer| eval "def explains.#{rollup}; map{|q|q[:#{rollup}]}.flatten.uniq; end" end return explains end For the eval line, I first tried explains.define_method, and it didn't work. Instead of researching why, or finding a kindler gentler system, I whipped out eval and put a bullet thru the problem. It's the shortest possible eval, anyway! Also I think you can't say 'def foo; def bar; end; end' - the def is in method-space, not class-space. -- Phlip