PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Failed Metaprogramming PLUS Stack Level Too Deep
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Failed Metaprogramming PLUS Stack Level Too Deep

Réponse
 
LinkBack Outils de la discussion
Vieux 14/09/2007, 12h25   #1
Ari Brown
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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


  Réponse avec citation
Vieux 14/09/2007, 15h05   #2
Jano Svitok
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Failed Metaprogramming PLUS Stack Level Too Deep

On 9/14/07, Ari Brown <ari@aribrown.com> wrote:
> def #{name} &b

- @chain = #{name}
+ @chain = "#{name}"
> @file << " # BEGIN rules for chain _#{name.upcase}_\n"
> instance_eval(&b)
> @file << " # END rules for chain _#{name.upcase}_\n"
> @chain = nil
> end


  Réponse avec citation
Vieux 14/09/2007, 15h20   #3
Marcin Raczkowski
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Failed Metaprogramming PLUS Stack Level Too Deep

stop metaprogramming
seriously metaprograming is nice and cool but usually leads to mistakes
if you are not expirienced programmer and don't have good imagination

try adding () here:
def #{name} &b => def #{name}(&b)

and you forgot to add "" here:
@chain = #{name}

should be:
@chain = '#{name}'

way you did it you made something like:

def raz &b
@chain = raz
.....

so method tried to run itself inifinitelly

next time try to "puts" or "p" your method before evaling it

  Réponse avec citation
Vieux 14/09/2007, 22h36   #4
Ari Brown
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Failed Metaprogramming PLUS Stack Level Too Deep


On Sep 14, 2007, at 10:05 AM, Jano Svitok wrote:

> On 9/14/07, Ari Brown <ari@aribrown.com> wrote:
>> def #{name} &b

> - @chain = #{name}
> + @chain = "#{name}"
>> @file << " # BEGIN rules for chain _#{name.upcase}_\n"
>> instance_eval(&b)
>> @file << " # END rules for chain _#{name.upcase}_\n"
>> @chain = nil
>> end


This is why I fail at life.

But the good thing (for me, at least) is that once I make this
mistake, it will almost never happen again.

If it does, please don't die in the mean time :-)

Thanks a bajillion,
~ Ari
English is like a pseudo-random number generator - there are a
bajillion rules to it, but nobody cares.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h47.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08624 seconds with 12 queries