From: Pedro Del Gallego Date: 2007-09-17T03:06:41+09:00 Subject: Re: blocks expected arguments and metaprogramming BTW, its works perfectly, with that i can decide what parameter return in advances, (but, yet, I dont know is a good idea or not) Thanks module Kernel def before (name, &block) define_method(name) do if block.arity == 1 yield :only_one elsif block.arity == 2 yield :one,:two elsif block.arity == -2 yield :one, :a , :splater, :argument end end end end class A before :foo do |first| puts first end end a = A.new a.foo class A before :foo do |first , second| puts second end end a2 = A.new a2.foo class A before :foo do |first , *splat_arg| puts splat_arg end end a3 = A.new a3.foo 2007/9/16, Pedro Del Gallego : > > > > On Sep 16, 8:10 am, "Pedro Del Gallego" > > wrote: > > > hi all, > > > > > > in this (http://pastie.caboo.se/97662) code : > > > > > > module Kernel > > > def expected_argument_list > > > 2 > > > end > > > > > def before (name, &blk) > > puts :hola > > define_method(name){ > > if blk.arity==1 > > yield :only_one > > else > > yield :one,:two > > end > > } > > end > > end > > > > It's not quite as simple as that but that should be enough to move you > > forward. > > Yes thats enough for me. I didnt now that the block was a Proc class. > > Thanks. > > > -- > ------------------------------------- > Pedro Del Gallego > > Email : pedro.delgallego@gmail.com > > -- ------------------------------------- Pedro Del Gallego Email : pedro.delgallego@gmail.com