From: Ari Brown Date: 2007-09-14T20:25:07+09:00 Subject: Failed Metaprogramming PLUS Stack Level Too Deep Hey all I'm trying to dynamically define a method which will do the following. Example: def INPUT(&b) @chain = "INPUT" @file << " # BEGIN rules for chain _INPUT_\n" instance_eval(&b) @file << " # END rules for chain _INPUT_\n" @chain = nil end So my plan is that I call chain "TEST_CHAIN" and it will create a dynamic method as such. However, due to my failure at life, liberty, and metaprogramming, I have to run through two commands in order to do this: def chain(name) Firewall.real_chain(name) $stderr.puts "Generating chain #{name} in table #{@table}" if @debug @file << "iptables -t #{@table} -N #{name} # Adding chain # {name}\n" end def Firewall.real_chain(*names) names.each do |name| module_eval <<-"end_eval" def #{name} &b @chain = #{name} @file << " # BEGIN rules for chain _#{name.upcase}_\n" instance_eval(&b) @file << " # END rules for chain _#{name.upcase}_\n" @chain = nil end end_eval end If I have module_eval in chain(), then I get an undefined method error. But here.... With this setup, I get a stack level too deep by calling: TEST_CHAIN do puts 5 end Or with any other block, for that matter. Bwah? My brain hurts! -------------------------------------------------------| ~ Ari crap my sig won't fit