So i try to define a methode by providing a bloc which can contain a
yield.
I got a error 'no block given (yield)' on yield execution
Here is my test code :
class B
def p1 ; puts "p1"; end
def p2 ; puts "p2 1" ; yield ; puts "p2 2" ; end
def self.add_tag(name,&blk)
puts "defined #{name}..."
define_method(name) do
instance_eval(&blk)
end
end
def self.add_tag2(name,str_bloc)
puts "defined2 #{name}..."
module_eval %{
def #{name}()
#{str_bloc}
end
}
end
end
This is known as the single biggest PITA of Ruby1.8, well by me.
If you can, use Ruby1.9 and you can do such wonderful things as
define_method :alpha do |beta, &gamma|
. .
gamma[...]
..
end
in 1.8. you have to do some nasty tricks with converting methods to
blocks or use simply "eval" or "module_eval" with a string.
HTH
R.
···
On Thu, Jun 3, 2010 at 3:28 PM, Regis d'Aubarede <regis.aubarede@gmail.com> wrote:
Hello,
So i try to define a methode by providing a bloc which can contain a
yield.