Blocks in class_eval

the following works:

///// BEGIN funcmeta.rb /////
def func_meta(&b)
class_eval {
@@proc = b #guilt begins here
def test
@@proc.call
end
}
end

class Test
func_meta { puts(“test”) }
end

t = Test.new
t.test
///// END funcmeta.rb /////

any clean way to do this without resorting to a class variable?

thanks in advance, you darned helpful people!

~Kyle

On Mon, 26 Feb 2007, Kyle Mitchell wrote:

end

thanks in advance, you darned helpful people!

harp:~ > cat a.rb
class Module
def func_meta m, &b
module_eval{ define_method m, &b }
end
end

class Test
func_meta(“test”){ puts “test” }
end

t = Test.new
t.test

harp:~ > ruby a.rb
test

-a

Kyle Mitchell wrote:

end

thanks in advance, you darned helpful people!

~Kyle

def func_meta(&b)
class_eval {
define_method :test, &b
}
end

class Test
func_meta { puts(“test”) }
end

t = Test.new
t.test