# Ruby eval function

**URL:** <https://www.ruby-forum.com/t/ruby-eval-function/187653>\
**Category:** Rails\
**Created:** [April 27, 2010, 1:28pm UTC](https://www.ruby-forum.com/t/ruby-eval-function/187653 "2010-04-27T13:28:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kevid](https://www.ruby-forum.com/u/kevid)\
**Post date:** [April 27, 2010, 1:28pm UTC](https://www.ruby-forum.com/t/ruby-eval-function/187653/1 "2010-04-27T13:28:31Z")

</div>

Hi all,

I have the code below from “mechanize gem” [the file is module.rb].  
am a newbie in ruby. Could anyone help me redesign the code below to  
use either  
(a) block eval OR (b) not use eval at all.

Thoughts ?

class Module  
def attr\_finder(\*syms)  
syms.each do |sym|  
class\_eval %{ def #{sym.to\_s}(hash = nil)  
if hash == nil  
@#{sym.to\_s}  
else  
@#{sym.to\_s}.find\_all do |t|  
found = true  
hash.each\_key { |key|  
found = false if t.send(key.to\_sym) !=  
hash[key]  
}  
found  
end  
end  
end  
}  
end  
end  
end
