Forum: Ruby class_exec for 1.8.6?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Henrik -. (Guest)
on 2008-10-08 23:56
(Received via mailing list)
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.
This topic is locked and can not be replied to.