Le jeudi 02 aoû¹ 2007 04:27 +0900, Andrea Maschio a ñÄrit :
> the problem is that method_name is a static call, i need to make it dynamic
> and choosed by the user/programmer, so at least he should type
> eval("method_name(arg1,arg2)") if condition
>
> but my aim was just to encapsulate this in a more comprehensible grammar
> like
>
> if_it_happens_that(is_true, "do_something(arg1,arg2)")
>
> in another language that english it sound more different using english word
> "like if, then, end, do"
>
> i know it could sound weird, but this was my need, and i solved it with eval
> (of course the internal logic is far more complex)
Do you want something like this :
---
def sendif( args, &bloc )
if args[:if]
send args[:then].shift, *args[:then], &bloc
else
send args[:else].shift, *args[:else], &bloc if args[:else]
end
end
sendif :if => 1 < 2, :then => [:p, "gagne"], :else => [:puts, "perdu"]
---
?
--
Etienne Vallette d'Osia