From: Brian Candler Date: 2010-04-27T21:01:10+09:00 Subject: Re: RUBY EVAL FUNCTION It's pretty reasonable to use eval in the code you provide. I think the method it defines will be faster because there is no closure created. But if you really want to avoid it: class Module def attr_finder(*syms) syms.each do |sym| define_method(sym) do |*args| val = instance_variable_get("@#{sym}") return val if args.empty? hash = args.first val.find_all do |t| found = true hash.each_key { |key| found = false if t.send(key) != hash[key] } found end end end end end # Test class Foo attr_finder :bar end f = Foo.new f.instance_eval { @bar = ["a","bb","cc"] } puts f.bar puts f.bar(:length => 2) I would also be inclined to simplify your finder loop to this: hash = args.first val.find_all { |t| !hash.find { |k,v| t.send(k) != v } } -- Posted via http://www.ruby-forum.com/.