# Class\_exec for 1.8.6?

**URL:** <https://www.ruby-forum.com/t/class-exec-for-1-8-6/150465>\
**Category:** Ruby\
**Created:** [October 8, 2008, 9:56pm UTC](https://www.ruby-forum.com/t/class-exec-for-1-8-6/150465 "2008-10-08T21:56:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![malesca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@malesca](https://www.ruby-forum.com/u/malesca)\
**Post date:** [October 8, 2008, 9:56pm UTC](https://www.ruby-forum.com/t/class-exec-for-1-8-6/150465/1 "2008-10-08T21:56:58Z")

</div>

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  
[GitHub - henrik/augmentations: Rails plugin that provides a simple API for extending a model/class from a module.](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.
