# Using lambda in class\_eval

**URL:** <https://www.ruby-forum.com/t/using-lambda-in-class-eval/137873>\
**Category:** Ruby\
**Created:** [May 17, 2008, 6:14am UTC](https://www.ruby-forum.com/t/using-lambda-in-class-eval/137873 "2008-05-17T06:14:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsoho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8baadc/32.png) [@jsoho](https://www.ruby-forum.com/u/jsoho)\
**Post date:** [May 17, 2008, 6:14am UTC](https://www.ruby-forum.com/t/using-lambda-in-class-eval/137873/1 "2008-05-17T06:14:21Z")

</div>

Hi All,

I’m looking to do something like:

def test(name, proc)  
class\_eval(\<\<-EOS, **FILE** , **LINE** )  
def #{name}\_string=(str)  
# do stuff, whatever  
self.#{name} = proc.call(str)  
end  
EOS  
end

and I want to call it like e.g.:

class Project  
attr\_accessor :due\_at  
test :due\_at, lamdba { |x| Time.parse(x) }  
end

and then:

Project.new.due\_at\_string = “2008-01-01 00:00”  
puts Project.new.due\_at # should result in a Time object

The problem I’m facing is: how can I call proc from within the  
interpolated string that is given to class\_eval ?? How should I write  
my class\_eval differently?

Best regards,  
Jimmy
