classKlassdefmethod_missing(method_name,*args,&block)ifmethod_name.to_s=~/^find_by_(.+)$/run_find_by_method($1,*args,&block)elsesuperendenddefrun_find_by_method(attrs,*args,&block)attrs=attrs.split('_and_')attrs_with_args=[attrs,args].transposeconditions=Hash[attrs_with_args]str=''conditions.each{|key,value|str+="#{key} = '#{value}' and "}p"select * from tbl where #{str[0..-6]}"endendk=Klass.newk.find_by_name("Bunlong")k.find_by_name_and_email("Bunlong","bunlong.van@gmail.com")