Class_exec for 1.8.6?


#1

In Ruby 1.8.6, I want to evaluate a block of code like

lambda {|x|
puts “x is #{x}”
def instance_method; end
def self.class_method; end
}

in a class, and have it define those methods and output the passed-in
value of x.

In other words, I want to do

MyKlass.class_eval(&block)

but also pass in a block argument.

To my understanding this is what class_exec does in 1.8.7 and 1.9.

I’ve seen pure-Ruby backports of instance_exec, but not of class_exec.
I’ve not been able to figure out how make a class_exec for 1.8.

Anyone?

The reason I want this is to add arguments to
http://github.com/henrik/augmentations/tree/master. I could work
around it with e.g. accessors, but I think the block argument syntax
would be the most intuitive.