Forum: Ruby class_exec for 1.8.6?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
4a551074ddba4460f95d011c47190d0e?d=identicon&s=25 Henrik --- (malesca)
on 2008-10-08 21: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


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.


The reason I want this is to add arguments to 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.