Ruby eval function

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs